MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / doJSON

Method doJSON

cmd/inject-cli/main.go:111–141  ·  view source on GitHub ↗
(method, path string, body any)

Source from the content-addressed store, hash-verified

109}
110
111func (c *apiClient) doJSON(method, path string, body any) ([]byte, error) {
112 var bodyReader io.Reader
113 if body != nil {
114 data, err := json.Marshal(body)
115 if err != nil {
116 return nil, err
117 }
118 bodyReader = bytes.NewReader(data)
119 }
120
121 req, err := http.NewRequest(method, c.baseURL+path, bodyReader)
122 if err != nil {
123 return nil, err
124 }
125 req.Header.Set("Content-Type", "application/json")
126 if c.secret != "" {
127 req.Header.Set("Authorization", "Bearer "+c.secret)
128 }
129
130 resp, err := c.http.Do(req)
131 if err != nil {
132 return nil, fmt.Errorf("request failed: %w", err)
133 }
134 defer resp.Body.Close()
135
136 data, _ := io.ReadAll(resp.Body)
137 if resp.StatusCode >= 400 {
138 return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(data))
139 }
140 return data, nil
141}
142
143func (c *apiClient) getSessions() ([]SessionSummary, error) {
144 data, err := c.doJSON("GET", "/v0/management/sessions", nil)

Callers 7

getSessionsMethod · 0.95
getSessionMethod · 0.95
execCommandMethod · 0.95
getObservedToolsMethod · 0.95
getRulesMethod · 0.95
patchRuleMethod · 0.95
deleteRuleMethod · 0.95

Calls 3

DoMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected