parseTransferEncoding sets t.Chunked based on the Transfer-Encoding header.
()
| 564 | |
| 565 | // parseTransferEncoding sets t.Chunked based on the Transfer-Encoding header. |
| 566 | func (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 |
no test coverage detected