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

Function streamResponseToSink

go/copilot_request_handler.go:218–240  ·  view source on GitHub ↗
(resp *http.Response, sink *responseSink)

Source from the content-addressed store, hash-verified

216}
217
218func streamResponseToSink(resp *http.Response, sink *responseSink) error {
219 if err := sink.start(resp.StatusCode, statusText(resp), cloneHeader(resp.Header)); err != nil {
220 return err
221 }
222 buf := make([]byte, 32*1024)
223 for {
224 n, readErr := resp.Body.Read(buf)
225 if n > 0 {
226 // writeText copies eagerly via string(...), so the reused read
227 // buffer can be passed directly without an extra per-chunk alloc.
228 if err := sink.writeText(buf[:n]); err != nil {
229 return err
230 }
231 }
232 if readErr == io.EOF {
233 break
234 }
235 if readErr != nil {
236 return sink.sinkError(readErr.Error(), "")
237 }
238 }
239 return sink.end()
240}
241
242func statusText(resp *http.Response) string {
243 return strings.TrimSpace(strings.TrimPrefix(resp.Status, strconv.Itoa(resp.StatusCode)))

Callers 1

handleHTTPMethod · 0.85

Calls 8

statusTextFunction · 0.85
cloneHeaderFunction · 0.85
writeTextMethod · 0.80
sinkErrorMethod · 0.80
startMethod · 0.45
ReadMethod · 0.45
ErrorMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…