MCPcopy Index your code
hub / github.com/coder/coder / ServeHTTP

Method ServeHTTP

aibridge/bridge.go:360–384  ·  view source on GitHub ↗

ServeHTTP exposes the internal http.Handler, which has all [Provider]s' routes registered. It also tracks inflight requests.

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

358// ServeHTTP exposes the internal http.Handler, which has all [Provider]s' routes registered.
359// It also tracks inflight requests.
360func (b *RequestBridge) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
361 select {
362 case <-b.closed:
363 http.Error(rw, "server closed", http.StatusInternalServerError)
364 return
365 default:
366 }
367
368 // We want to abide by the context passed in without losing any of its
369 // functionality, but we still want to link our shutdown context to each
370 // request.
371 ctx := mergeContexts(r.Context(), b.inflightCtx)
372
373 b.inflightReqs.Add(1)
374 b.inflightWG.Add(1)
375 defer func() {
376 b.inflightReqs.Add(-1)
377 b.inflightWG.Done()
378 }()
379
380 // Enforce the request body size limit. MaxBytesReader counts bytes as
381 // they are read from the connection and fails when the limit is exceeded.
382 r.Body = http.MaxBytesReader(rw, r.Body, maxRequestBodyBytes)
383 b.mux.ServeHTTP(rw, r.WithContext(ctx))
384}
385
386// Shutdown will attempt to gracefully shutdown. This entails waiting for all requests to
387// complete, and shutting down the MCP server proxier.

Callers 15

TestRequestBodySizeLimitFunction · 0.95
TestPassthroughRoutesFunction · 0.45
newPassthroughRouterFunction · 0.45
postStartFunction · 0.45
getListFunction · 0.45
getOutputFunction · 0.45
getOutputWithHeadersFunction · 0.45
postSignalFunction · 0.45

Calls 6

mergeContextsFunction · 0.85
WithContextMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45
DoneMethod · 0.45

Tested by 15

TestRequestBodySizeLimitFunction · 0.76
TestPassthroughRoutesFunction · 0.36
postStartFunction · 0.36
getListFunction · 0.36
getOutputFunction · 0.36
getOutputWithHeadersFunction · 0.36
postSignalFunction · 0.36
TestStartProcessFunction · 0.36