var ErrLineTooLong … type errorReader … func (r errorReader) Read(p []byte) (n int, err error) { … } type byteReader … func (br *byteReader) Read(p []byte) (n int, err error) { … } type transferWriter … func newTransferWriter(r any) (t *transferWriter, err error) { … } // shouldSendChunkedRequestBody reports whether we should try to send a // chunked request body to the server. In particular, the case we really // want to prevent is sending a GET or other typically-bodyless request to a // server with a chunked body when the body has zero bytes, since GETs with // bodies (while acceptable according to specs), even zero-byte chunked // bodies, are approximately never seen in the wild and confuse most // servers. See Issue 18257, as one example. // // The only reason we'd send such a request is if the user set the Body to a // non-nil value (say, io.NopCloser(bytes.NewReader(nil))) and didn't // set ContentLength, or NewRequest set it to -1 (unknown), so then we assume // there's bytes to send. // // This code tries to read a byte from the Request.Body in such cases to see // whether the body actually has content (super rare) or is actually just // a non-nil content-less ReadCloser (the more common case). In that more // common case, we act as if their Body were nil instead, and don't send // a body. func (t *transferWriter) shouldSendChunkedRequestBody() bool { … } // probeRequestBody reads a byte from t.Body to see whether it's empty // (returns io.EOF right away). // // But because we've had problems with this blocking users in the past // (issue 17480) when the body is a pipe (perhaps waiting on the response // headers before the pipe is fed data), we need to be careful and bound how // long we wait for it. This delay will only affect users if all the following // are true: // - the request body blocks // - the content length is not set (or set to -1) // - the method doesn't usually have a body (GET, HEAD, DELETE, ...) // - there is no transfer-encoding=chunked already set. // // In other words, this delay will not normally affect anybody, and there // are workarounds if it does. func (t *transferWriter) probeRequestBody() { … } func noResponseBodyExpected(requestMethod string) bool { … } func (t *transferWriter) shouldSendContentLength() bool { … } func (t *transferWriter) writeHeader(w io.Writer, trace *httptrace.ClientTrace) error { … } // always closes t.BodyCloser func (t *transferWriter) writeBody(w io.Writer) (err error) { … } // doBodyCopy wraps a copy operation, with any resulting error also // being saved in bodyReadError. // // This function is only intended for use in writeBody. func (t *transferWriter) doBodyCopy(dst io.Writer, src io.Reader) (n int64, err error) { … } // unwrapBody unwraps the body's inner reader if it's a // nopCloser. This is to ensure that body writes sourced from local // files (*os.File types) are properly optimized. // // This function is only intended for use in writeBody. func (t *transferWriter) unwrapBody() io.Reader { … } type transferReader … func (t *transferReader) protoAtLeast(m, n int) bool { … } // bodyAllowedForStatus reports whether a given response status code // permits a body. See RFC 7230, section 3.3. func bodyAllowedForStatus(status int) bool { … } var suppressedHeaders304 … var suppressedHeadersNoBody … var excludedHeadersNoBody … func suppressedHeaders(status int) []string { … } // msg is *Request or *Response. func readTransfer(msg any, r *bufio.Reader) (err error) { … } // Checks whether chunked is part of the encodings stack. func chunked(te []string) bool { … } // Checks whether the encoding is explicitly "identity". func isIdentity(te []string) bool { … } type unsupportedTEError … func (uste *unsupportedTEError) Error() string { … } // isUnsupportedTEError checks if the error is of type // unsupportedTEError. It is usually invoked with a non-nil err. func isUnsupportedTEError(err error) bool { … } // parseTransferEncoding sets t.Chunked based on the Transfer-Encoding header. func (t *transferReader) parseTransferEncoding() error { … } // Determine the expected body length, using RFC 7230 Section 3.3. This // function is not a method, because ultimately it should be shared by // ReadResponse and ReadRequest. func fixLength(isResponse bool, status int, requestMethod string, header Header, chunked bool) (n int64, err error) { … } // Determine whether to hang up after sending a request and body, or // receiving a response and body // 'header' is the request headers. func shouldClose(major, minor int, header Header, removeCloseHeader bool) bool { … } // Parse the trailer header. func fixTrailer(header Header, chunked bool) (Header, error) { … } type body … var ErrBodyReadAfterClose … func (b *body) Read(p []byte) (n int, err error) { … } // Must hold b.mu. func (b *body) readLocked(p []byte) (n int, err error) { … } var singleCRLF … var doubleCRLF … func seeUpcomingDoubleCRLF(r *bufio.Reader) bool { … } var errTrailerEOF … func (b *body) readTrailer() error { … } func mergeSetHeader(dst *Header, src Header) { … } // unreadDataSizeLocked returns the number of bytes of unread input. // It returns -1 if unknown. // b.mu must be held. func (b *body) unreadDataSizeLocked() int64 { … } func (b *body) Close() error { … } func (b *body) didEarlyClose() bool { … } // bodyRemains reports whether future Read calls might // yield data. func (b *body) bodyRemains() bool { … } func (b *body) registerOnHitEOF(fn func()) { … } type bodyLocked … func (bl bodyLocked) Read(p []byte) (n int, err error) { … } var httplaxcontentlength … // parseContentLength checks that the header is valid and then trims // whitespace. It returns -1 if no value is set otherwise the value // if it's >= 0. func parseContentLength(clHeaders []string) (int64, error) { … } type finishAsyncByteRead … func (fr finishAsyncByteRead) Read(p []byte) (n int, err error) { … } var nopCloserType … var nopCloserWriterToType … // unwrapNopCloser return the underlying reader and true if r is a NopCloser // else it return false. func unwrapNopCloser(r io.Reader) (underlyingReader io.Reader, isNopCloser bool) { … } // isKnownInMemoryReader reports whether r is a type known to not // block on Read. Its caller uses this as an optional optimization to // send fewer TCP packets. func isKnownInMemoryReader(r io.Reader) bool { … } type bufioFlushWriter … func (fw bufioFlushWriter) Write(p []byte) (n int, err error) { … }