MCPcopy Create free account
hub / github.com/coder/coder / handle

Method handle

aibridge/internal/integrationtest/mockupstream.go:146–189  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

144}
145
146func (ms *mockUpstream) handle(w http.ResponseWriter, r *http.Request) {
147 call := int(ms.Calls.Add(1) - 1)
148
149 body, err := io.ReadAll(r.Body)
150 defer r.Body.Close()
151 require.NoError(ms.t, err)
152
153 ms.mu.Lock()
154 ms.requests = append(ms.requests, receivedRequest{
155 Method: r.Method,
156 Path: r.URL.Path,
157 Header: r.Header.Clone(),
158 Body: append([]byte(nil), body...),
159 })
160 ms.mu.Unlock()
161
162 validateRequest(ms.t, call, r.URL.Path, body)
163
164 resp := ms.responseForCall(call)
165 if resp.OnRequest != nil {
166 resp.OnRequest(r, body)
167 }
168
169 if isStreaming(body, r.URL.Path) {
170 require.NotEmpty(ms.t, resp.Streaming, "response #%d: Streaming body is empty (fixture missing streaming response?)", call+1)
171 if isRawHTTPResponse(resp.Streaming) {
172 ms.writeRawHTTPResponse(w, r, resp.Streaming)
173 return
174 }
175 ms.writeSSE(w, resp.Streaming)
176 return
177 }
178
179 require.NotEmpty(ms.t, resp.Blocking, "response #%d: Blocking body is empty (fixture missing non-streaming response?)", call+1)
180 if isRawHTTPResponse(resp.Blocking) {
181 ms.writeRawHTTPResponse(w, r, resp.Blocking)
182 return
183 }
184
185 status := cmp.Or(ms.StatusCode, http.StatusOK)
186 w.Header().Set("Content-Type", "application/json")
187 w.WriteHeader(status)
188 _, _ = w.Write(resp.Blocking)
189}
190
191func (ms *mockUpstream) responseForCall(call int) upstreamResponse {
192 if call >= len(ms.responses) {

Callers

nothing calls this directly

Calls 15

responseForCallMethod · 0.95
writeRawHTTPResponseMethod · 0.95
writeSSEMethod · 0.95
validateRequestFunction · 0.85
isStreamingFunction · 0.85
isRawHTTPResponseFunction · 0.85
NotEmptyMethod · 0.80
AddMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
ReadAllMethod · 0.45

Tested by

no test coverage detected