MCPcopy Index your code
hub / github.com/github/copilot-sdk / buildHTTPRequest

Function buildHTTPRequest

go/copilot_request_handler.go:185–208  ·  view source on GitHub ↗
(rctx *CopilotRequestContext)

Source from the content-addressed store, hash-verified

183}
184
185func 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
210func drainBody(ch <-chan CopilotWebSocketMessage) []byte {
211 var buf bytes.Buffer

Callers 1

handleHTTPMethod · 0.85

Calls 3

isForbiddenRequestHeaderFunction · 0.85
drainBodyFunction · 0.70
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…