MCPcopy Create free account
hub / github.com/imroc/req / processHeaders

Method processHeaders

internal/http2/transport.go:2415–2471  ·  view source on GitHub ↗
(f *MetaHeadersFrame)

Source from the content-addressed store, hash-verified

2413}
2414
2415func (rl *clientConnReadLoop) processHeaders(f *MetaHeadersFrame) error {
2416 cs := rl.streamByID(f.StreamID)
2417 if cs == nil {
2418 // We'd get here if we canceled a request while the
2419 // server had its response still in flight. So if this
2420 // was just something we canceled, ignore it.
2421 return nil
2422 }
2423 if cs.readClosed {
2424 rl.endStreamError(cs, StreamError{
2425 StreamID: f.StreamID,
2426 Code: ErrCodeProtocol,
2427 Cause: errors.New("protocol error: headers after END_STREAM"),
2428 })
2429 return nil
2430 }
2431 if !cs.firstByte {
2432 if cs.trace != nil {
2433 // TODO(bradfitz): move first response byte earlier,
2434 // when we first read the 9 byte header, not waiting
2435 // until all the HEADERS+CONTINUATION frames have been
2436 // merged. This works for now.
2437 traceFirstResponseByte(cs.trace)
2438 }
2439 cs.firstByte = true
2440 }
2441 if !cs.pastHeaders {
2442 cs.pastHeaders = true
2443 } else {
2444 return rl.processTrailers(cs, f)
2445 }
2446
2447 res, err := rl.handleResponse(cs, f)
2448 if err != nil {
2449 if _, ok := err.(ConnectionError); ok {
2450 return err
2451 }
2452 // Any other error type is a stream error.
2453 rl.endStreamError(cs, StreamError{
2454 StreamID: f.StreamID,
2455 Code: ErrCodeProtocol,
2456 Cause: err,
2457 })
2458 return nil // return nil from process* funcs to keep conn alive
2459 }
2460 if res == nil {
2461 // (nil, nil) special case. See handleResponse docs.
2462 return nil
2463 }
2464 cs.resTrailer = &res.Trailer
2465 cs.res = res
2466 close(cs.respHeaderRecv)
2467 if f.StreamEnded() {
2468 rl.endStream(cs)
2469 }
2470 return nil
2471}
2472

Callers 1

runMethod · 0.95

Calls 7

streamByIDMethod · 0.95
endStreamErrorMethod · 0.95
processTrailersMethod · 0.95
handleResponseMethod · 0.95
endStreamMethod · 0.95
traceFirstResponseByteFunction · 0.85
StreamEndedMethod · 0.65

Tested by

no test coverage detected