Documentation
¶
Index ¶
- Constants
- Variables
- func BuildHeaderRange(start, end, totalSize uint64) string
- func ClientIP(remoteAddr string, header http.Header) string
- func CopyHeader(dst, src http.Header)
- func CopyHeadersWithout(dst, src http.Header, excludeKeys ...string)
- func CopyTrailer(dst, src http.Header)
- func IsChunked(h http.Header) bool
- func NewBizError(code int, headers http.Header) error
- func ParseCacheTime(withKey string, src http.Header) (time.Duration, bool)
- func PrintRoutes(mux *http.ServeMux)
- func RemoveHopByHopHeaders(h http.Header)
- func ResponseHeaderSize(code int, hdr http.Header) uint64
- func Scheme(r *http.Request) string
- func WithTracer(req *http.Request) *http.Request
- type BizError
- type ContentRange
- type Parser
- type Range
- type ResponseRecorder
- func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *ResponseRecorder) SentBytes() uint64
- func (r *ResponseRecorder) Size() uint64
- func (r *ResponseRecorder) Status() int
- func (r *ResponseRecorder) Write(b []byte) (n int, err error)
- func (r *ResponseRecorder) WriteHeader(s int)
Constants ¶
const DefaultProtocolCacheTime = time.Second * 300
Variables ¶
var ( ErrContentRangeHeaderNotFound = errors.New("Content-Range header not found") ErrContentRangeInvalidFormat = errors.New("Content-Range invalid format") ErrContentRangeInvalidStartValue = errors.New("Content-Range invalid start value") ErrContentRangeInvalidEndValue = errors.New("Content-Range invalid end value") ErrContentRangeInvalidTotalValue = errors.New("Content-Range invalid total value") ErrRangeHeaderNotFound = errors.New("header Range not found") ErrRangeHeaderInvalidFormat = errors.New("header Range invalid format") ErrRangeHeaderUnsatisfiable = errors.New("header Range unsatisfiable") )
var ( Parse = parser.Parse SingleRange = parser.SingleParse )
Functions ¶
func BuildHeaderRange ¶
BuildRange builds the Range header value.
func CopyHeader ¶
CopyHeader copies all headers from the source http.Header to the destination http.Header. It iterates over each header key-value pair in the source and adds them to the destination.
func CopyHeadersWithout ¶
CopyHeadersWithout copies all headers from the source http.Header to the destination http.Header, excluding the headers specified in excludeKeys. It creates a map of excluded keys for efficient lookup and skips those keys during the copy process.
- dst: The destination http.Header where the headers will be copied to. - src: The source http.Header from which the headers will be copied. - excludeKeys: A variadic list of header keys to be excluded from copying.
Example usage:
src := http.Header{
"Content-Type": {"application/json"},
"Content-Length": {"123"},
"Authorization": {"Bearer token"},
}
dst := http.Header{}
CopyHeadersWithout(dst, src, "Authorization", "Content-Length")
// dst will now contain only "Content-Type": {"application/json"}
func CopyTrailer ¶
CopyTrailer copies all headers from the source http.Header to the destination http.Header, prefixing each header key with the http.TrailerPrefix. This function is useful for handling HTTP trailers, which are headers sent after the body of an HTTP message.
see https://pkg.go.dev/net/http#example-ResponseWriter-Trailers
- dst: The destination http.Header where the headers will be copied to. - src: The source http.Header from which the headers will be copied.
Example usage:
src := http.Header{
"Example-Key": {"Example-Value"},
}
dst := http.Header{}
CopyTrailer(dst, src)
// dst will now contain "Trailer-Example-Key": {"Example-Value"}
func IsChunked ¶
IsChunked checks if the Transfer-Encoding header is chunked.
see https://www.rfc-editor.org/rfc/rfc9112.html#name-chunked-transfer-coding
func ParseCacheTime ¶
ParseCacheTime parses cache time from HTTP headers.
If withKey is empty, it will parse from standard Cache-Control and Expires headers. If withKey is provided, it will look for that specific header key to determine cache time.
It returns the parsed cache duration and a boolean indicating whether caching is allowed.
func PrintRoutes ¶
func RemoveHopByHopHeaders ¶
RemoveHopByHopHeaders removes hop-by-hop headers.
Types ¶
type BizError ¶
func ParseBizError ¶
type ContentRange ¶
func ParseContentRange ¶
func ParseContentRange(header http.Header) (ContentRange, error)
ParseContentRange parses the Content-Range header from an HTTP response.
func (*ContentRange) String ¶
func (cr *ContentRange) String() string
type Parser ¶
type Parser interface {
Parse(header string, size uint64) ([]*Range, error)
SingleParse(header string, size uint64) (*Range, error)
}
func NewUnsatisfiableParser ¶
func NewUnsatisfiableParser() Parser
type Range ¶
type Range struct {
Start, End int64
}
func NewRequestRange ¶
func UnsatisfiableMultiRange ¶
UnsatisfiableMultiRange ...
func (*Range) ContentRange ¶
func (*Range) MimeHeader ¶
func (r *Range) MimeHeader(contentType string, size uint64) textproto.MIMEHeader
func (*Range) RangeLength ¶
type ResponseRecorder ¶
type ResponseRecorder struct {
http.Hijacker
http.ResponseWriter
// contains filtered or unexported fields
}
func NewResponseRecorder ¶
func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder
func (*ResponseRecorder) Hijack ¶
func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements http.Hijacker.
func (*ResponseRecorder) SentBytes ¶
func (r *ResponseRecorder) SentBytes() uint64
func (*ResponseRecorder) Size ¶
func (r *ResponseRecorder) Size() uint64
func (*ResponseRecorder) Status ¶
func (r *ResponseRecorder) Status() int
func (*ResponseRecorder) WriteHeader ¶
func (r *ResponseRecorder) WriteHeader(s int)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cachecontrol provides HTTP Cache-Control header parsing with some utility functions to quickly deal with directives values.
|
Package cachecontrol provides HTTP Cache-Control header parsing with some utility functions to quickly deal with directives values. |