(ctx context.Context, req pluginapi.HTTPRequest)
| 106 | } |
| 107 | |
| 108 | func (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 | |
| 138 | func (c *hostHTTPClient) recordHTTPRequest(ctx context.Context, cfg *config.Config, req *http.Request, body []byte) { |
| 139 | if req == nil { |
no test coverage detected