(rctx *CopilotRequestContext)
| 183 | } |
| 184 | |
| 185 | func buildHTTPRequest(rctx *CopilotRequestContext) (*http.Request, error) { |
| 186 | body := drainBody(rctx.body) |
| 187 | method := strings.ToUpper(rctx.Method) |
| 188 | var bodyReader io.Reader |
| 189 | if len(body) > 0 && method != http.MethodGet && method != http.MethodHead { |
| 190 | bodyReader = bytes.NewReader(body) |
| 191 | } |
| 192 | httpReq, err := http.NewRequestWithContext(rctx.Context, method, rctx.URL, bodyReader) |
| 193 | if err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | // Attach rctx so custom RoundTripper implementations can read metadata |
| 197 | // (e.g. SessionID) via [RequestContextFrom]. |
| 198 | httpReq = httpReq.WithContext(context.WithValue(httpReq.Context(), copilotContextKey{}, rctx)) |
| 199 | for name, values := range rctx.Headers { |
| 200 | if isForbiddenRequestHeader(name) { |
| 201 | continue |
| 202 | } |
| 203 | for _, v := range values { |
| 204 | httpReq.Header.Add(name, v) |
| 205 | } |
| 206 | } |
| 207 | return httpReq, nil |
| 208 | } |
| 209 | |
| 210 | func drainBody(ch <-chan CopilotWebSocketMessage) []byte { |
| 211 | var buf bytes.Buffer |
no test coverage detected
searching dependent graphs…