(ctx context.Context, req pluginapi.HTTPRequest)
| 29 | } |
| 30 | |
| 31 | func (c *hostHTTPClient) Do(ctx context.Context, req pluginapi.HTTPRequest) (pluginapi.HTTPResponse, error) { |
| 32 | if ctx == nil { |
| 33 | ctx = context.Background() |
| 34 | } |
| 35 | resp, cfg, errDo := c.doHTTP(ctx, req) |
| 36 | if errDo != nil { |
| 37 | return pluginapi.HTTPResponse{}, errDo |
| 38 | } |
| 39 | defer func() { |
| 40 | if errClose := resp.Body.Close(); errClose != nil { |
| 41 | log.Warnf("pluginhost: response body close error: %v", errClose) |
| 42 | } |
| 43 | }() |
| 44 | helps.RecordAPIResponseMetadata(ctx, cfg, resp.StatusCode, resp.Header.Clone()) |
| 45 | body, errReadAll := io.ReadAll(resp.Body) |
| 46 | if len(body) > 0 { |
| 47 | helps.AppendAPIResponseChunk(ctx, cfg, body) |
| 48 | } |
| 49 | if errReadAll != nil { |
| 50 | helps.RecordAPIResponseError(ctx, cfg, errReadAll) |
| 51 | return pluginapi.HTTPResponse{}, fmt.Errorf("read host http response: %w", errReadAll) |
| 52 | } |
| 53 | return pluginapi.HTTPResponse{ |
| 54 | StatusCode: resp.StatusCode, |
| 55 | Headers: cloneHeader(resp.Header), |
| 56 | Body: body, |
| 57 | }, nil |
| 58 | } |
| 59 | |
| 60 | func (c *hostHTTPClient) DoStream(ctx context.Context, req pluginapi.HTTPRequest) (pluginapi.HTTPStreamResponse, error) { |
| 61 | if ctx == nil { |
nothing calls this directly
no test coverage detected