MCPcopy Index your code
hub / github.com/imroc/req / parseTransferEncoding

Method parseTransferEncoding

transfer.go:566–591  ·  view source on GitHub ↗

parseTransferEncoding sets t.Chunked based on the Transfer-Encoding header.

()

Source from the content-addressed store, hash-verified

564
565// parseTransferEncoding sets t.Chunked based on the Transfer-Encoding header.
566func (t *transferReader) parseTransferEncoding() error {
567 raw, present := t.Header["Transfer-Encoding"]
568 if !present {
569 return nil
570 }
571 delete(t.Header, "Transfer-Encoding")
572
573 // Issue 12785; ignore Transfer-Encoding on HTTP/1.0 requests.
574 if !t.protoAtLeast(1, 1) {
575 return nil
576 }
577
578 // Like nginx, we only support a single Transfer-Encoding header field, and
579 // only if set to "chunked". This is one of the most security sensitive
580 // surfaces in HTTP/1.1 due to the risk of request smuggling, so we keep it
581 // strict and simple.
582 if len(raw) != 1 {
583 return &unsupportedTEError{fmt.Sprintf("too many transfer encodings: %q", raw)}
584 }
585 if !ascii.EqualFold(raw[0], "chunked") {
586 return &unsupportedTEError{fmt.Sprintf("unsupported transfer encoding: %q", raw[0])}
587 }
588
589 t.Chunked = true
590 return nil
591}
592
593// Determine the expected body length, using RFC 7230 Section 3.3. This
594// function is not a method, because ultimately it should be shared by

Callers 1

readTransferFunction · 0.95

Calls 2

protoAtLeastMethod · 0.95
EqualFoldFunction · 0.92

Tested by

no test coverage detected