(r *http.Request)
| 71 | } |
| 72 | |
| 73 | func newTransferWriter(r *http.Request) (t *transferWriter, err error) { |
| 74 | t = &transferWriter{} |
| 75 | |
| 76 | // Extract relevant fields |
| 77 | atLeastHTTP11 := false |
| 78 | if r.ContentLength != 0 && r.Body == nil { |
| 79 | return nil, fmt.Errorf("http: Request.ContentLength=%d with nil Body", r.ContentLength) |
| 80 | } |
| 81 | t.Method = valueOrDefault(r.Method, "GET") |
| 82 | t.Close = r.Close |
| 83 | t.TransferEncoding = r.TransferEncoding |
| 84 | t.Header = r.Header |
| 85 | t.Trailer = r.Trailer |
| 86 | t.Body = r.Body |
| 87 | t.BodyCloser = r.Body |
| 88 | t.ContentLength = outgoingLength(r) |
| 89 | if t.ContentLength < 0 && len(t.TransferEncoding) == 0 && t.shouldSendChunkedRequestBody() { |
| 90 | t.TransferEncoding = []string{"chunked"} |
| 91 | } |
| 92 | // If there's a body, conservatively flush the headers |
| 93 | // to any bufio.Writer we're writing to, just in case |
| 94 | // the server needs the headers early, before we copy |
| 95 | // the body and possibly block. We make an exception |
| 96 | // for the common standard library in-memory types, |
| 97 | // though, to avoid unnecessary TCP packets on the |
| 98 | // wire. (Issue 22088.) |
| 99 | if t.ContentLength != 0 && !isKnownInMemoryReader(t.Body) { |
| 100 | t.FlushHeaders = true |
| 101 | } |
| 102 | |
| 103 | atLeastHTTP11 = true // Transport requests are always 1.1 or 2.0 |
| 104 | |
| 105 | // Sanitize Body,ContentLength,TransferEncoding |
| 106 | if !atLeastHTTP11 || t.Body == nil { |
| 107 | t.TransferEncoding = nil |
| 108 | } |
| 109 | if chunked(t.TransferEncoding) { |
| 110 | t.ContentLength = -1 |
| 111 | } else if t.Body == nil { // no chunking, no body |
| 112 | t.ContentLength = 0 |
| 113 | } |
| 114 | |
| 115 | // Sanitize Trailer |
| 116 | if !chunked(t.TransferEncoding) { |
| 117 | t.Trailer = nil |
| 118 | } |
| 119 | |
| 120 | return t, nil |
| 121 | } |
| 122 | |
| 123 | // shouldSendChunkedRequestBody reports whether we should try to send a |
| 124 | // chunked request body to the server. In particular, the case we really |
no test coverage detected
searching dependent graphs…