MCPcopy Create free account
hub / github.com/coder/aibridge / ServeHTTP

Method ServeHTTP

bridge.go:288–309  ·  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

286// ServeHTTP exposes the internal http.Handler, which has all [Provider]s' routes registered.
287// It also tracks inflight requests.
288func (b *RequestBridge) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
289 select {
290 case <-b.closed:
291 http.Error(rw, "server closed", http.StatusInternalServerError)
292 return
293 default:
294 }
295
296 // We want to abide by the context passed in without losing any of its
297 // functionality, but we still want to link our shutdown context to each
298 // request.
299 ctx := mergeContexts(r.Context(), b.inflightCtx)
300
301 b.inflightReqs.Add(1)
302 b.inflightWG.Add(1)
303 defer func() {
304 b.inflightReqs.Add(-1)
305 b.inflightWG.Done()
306 }()
307
308 b.mux.ServeHTTP(rw, r.WithContext(ctx))
309}
310
311// Shutdown will attempt to gracefully shutdown. This entails waiting for all requests to
312// complete, and shutting down the MCP server proxier.

Callers 4

TestPassthroughRoutesFunction · 0.80
newPassthroughRouterFunction · 0.80
actorMiddlewareFunction · 0.80

Calls 2

mergeContextsFunction · 0.85
ErrorMethod · 0.45

Tested by 2

TestPassthroughRoutesFunction · 0.64