MCPcopy Create free account
hub / github.com/cli/cli / recordingHandler

Function recordingHandler

script/api-host-gateway/gateway/main.go:131–143  ·  view source on GitHub ↗

recordingHandler attaches a record to the request context so the proxy can fill in the outcome, then writes exactly one line per request once the proxy is done with it.

(proxy http.Handler, rec *recorder)

Source from the content-addressed store, hash-verified

129// fill in the outcome, then writes exactly one line per request once the proxy
130// is done with it.
131func recordingHandler(proxy http.Handler, rec *recorder) http.Handler {
132 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
133 entry := &record{
134 Time: time.Now().UTC().Format(time.RFC3339Nano),
135 Method: r.Method,
136 Path: r.URL.RequestURI(),
137 Host: r.Host,
138 AuthHeader: r.Header.Get("Authorization") != "",
139 }
140 proxy.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), recordKey{}, entry)))
141 rec.Write(entry)
142 })
143}
144
145// newProxy builds the reverse proxy. The upstream URL carries the canonical
146// host that requests are forwarded to and that responses are rewritten from,

Callers 3

runFunction · 0.85

Calls 3

ServeHTTPMethod · 0.80
GetMethod · 0.65
WriteMethod · 0.65