internal

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package internal contains HTTP internals shared by net/http and net/http/httputil.

Index

Constants

View Source
const SniffLen = 512

The algorithm uses at most SniffLen bytes to make its decision.

Variables

View Source
var (
	ErrAbortHandler    = errors.New("net/http: abort Handler")
	ErrBodyNotAllowed  = errors.New("http: request method or response status code does not allow body")
	ErrRequestCanceled = errors.New("net/http: request canceled")
	ErrSkipAltProtocol = errors.New("net/http: skip alternate protocol")
)
View Source
var ErrLineTooLong = errors.New("header line too long")

Functions

func DetectContentType added in v0.12.0

func DetectContentType(data []byte) string

DetectContentType implements the algorithm described at https://mimesniff.spec.whatwg.org/ to determine the Content-Type of the given data. It considers at most the first 512 bytes of data. DetectContentType always returns a valid MIME type: if it cannot determine a more specific one, it returns "application/octet-stream".

func NewChunkedReader

func NewChunkedReader(r io.Reader) io.Reader

NewChunkedReader returns a new chunkedReader that translates the data read from r out of HTTP "chunked" format before returning it. The chunkedReader returns io.EOF when the final 0-length chunk is read.

NewChunkedReader is not needed by normal applications. The http package automatically decodes chunking when reading response bodies.

func NewChunkedWriter

func NewChunkedWriter(w io.Writer) io.WriteCloser

NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP "chunked" format before writing them to w. Closing the returned chunkedWriter sends the final 0-length chunk that marks the end of the stream but does not send the final CRLF that appears after trailers; trailers and the last CRLF must be written separately.

NewChunkedWriter is not needed by normal applications. The http package adds chunking automatically if handlers don't set a Content-Length header. Using newChunkedWriter inside a handler would result in double chunking or chunking with a Content-Length length, both of which are wrong.

Types

type FlushAfterChunkWriter

type FlushAfterChunkWriter struct {
	*bufio.Writer
}

FlushAfterChunkWriter signals from the caller of NewChunkedWriter that each chunk should be followed by a flush. It is used by the net/http.Transport code to keep the buffering behavior for headers and trailers, but flush out chunks aggressively in the middle for request bodies which may be generated slowly. See Issue 6574.

Directories

Path Synopsis
Package bisect can be used by compilers and other programs to serve as a target for the bisect debugging tool.
Package bisect can be used by compilers and other programs to serve as a target for the bisect debugging tool.
Package fakerace fakes out the internal/race package.
Package fakerace fakes out the internal/race package.
Package gate contains an alternative condition variable.
Package gate contains an alternative condition variable.
Package godebug makes the settings in the $GODEBUG environment variable available to other packages.
Package godebug makes the settings in the $GODEBUG environment variable available to other packages.
Package godebugs provides a table of known GODEBUG settings, for use by a variety of other packages, including internal/godebug, runtime, runtime/metrics, and cmd/go/internal/load.
Package godebugs provides a table of known GODEBUG settings, for use by a variety of other packages, including internal/godebug, runtime, runtime/metrics, and cmd/go/internal/load.
Package http2 implements the HTTP/2 protocol.
Package http2 implements the HTTP/2 protocol.
Package nettrace provides internal tracing hooks for net package.
Package nettrace provides internal tracing hooks for net package.
Package safefilepath manipulates operating-system file paths.
Package safefilepath manipulates operating-system file paths.
Package testcert contains a test-only localhost certificate.
Package testcert contains a test-only localhost certificate.
Package testenv emulates some testenv properties to reduce the amount of deleted line with respect to upstream.
Package testenv emulates some testenv properties to reduce the amount of deleted line with respect to upstream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL