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

Method doHTTP

internal/pluginhost/http_bridge.go:108–136  ·  view source on GitHub ↗
(ctx context.Context, req pluginapi.HTTPRequest)

Source from the content-addressed store, hash-verified

106}
107
108func (c *hostHTTPClient) doHTTP(ctx context.Context, req pluginapi.HTTPRequest) (*http.Response, *config.Config, error) {
109 if c == nil || c.host == nil {
110 return nil, nil, fmt.Errorf("host http client is unavailable")
111 }
112 if ctx == nil {
113 ctx = context.Background()
114 }
115 cfg := c.host.currentRuntimeConfig()
116 method := req.Method
117 if method == "" {
118 method = http.MethodGet
119 }
120 httpReq, errNewRequest := http.NewRequestWithContext(ctx, method, req.URL, bytes.NewReader(bytes.Clone(req.Body)))
121 if errNewRequest != nil {
122 return nil, cfg, fmt.Errorf("create host http request: %w", errNewRequest)
123 }
124 httpReq.Header = cloneHeader(req.Headers)
125 c.recordHTTPRequest(ctx, cfg, httpReq, req.Body)
126 client := helps.NewProxyAwareHTTPClient(ctx, cfg, c.auth, 0)
127 if client == nil {
128 client = &http.Client{}
129 }
130 resp, errDo := client.Do(httpReq)
131 if errDo != nil {
132 helps.RecordAPIResponseError(ctx, cfg, errDo)
133 return nil, cfg, fmt.Errorf("execute host http request: %w", errDo)
134 }
135 return resp, cfg, nil
136}
137
138func (c *hostHTTPClient) recordHTTPRequest(ctx context.Context, cfg *config.Config, req *http.Request, body []byte) {
139 if req == nil {

Callers 2

DoMethod · 0.95
DoStreamMethod · 0.95

Calls 7

recordHTTPRequestMethod · 0.95
NewProxyAwareHTTPClientFunction · 0.92
RecordAPIResponseErrorFunction · 0.92
currentRuntimeConfigMethod · 0.80
cloneHeaderFunction · 0.70
DoMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected