httputils

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 27, 2016 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyHeaders

func CopyHeaders(from, to http.Header)

CopyHeaders copies all headers from `from` to `to`.

func CopyHeadersWithout

func CopyHeadersWithout(from, to http.Header, exceptions ...string)

CopyHeadersWithout copies headers from `from` to `to` except for the `exceptions`

func Error

func Error(w http.ResponseWriter, code int)

Error is short for http.Error(w, http.StatusText(code), code)

func GetHopByHopHeaders

func GetHopByHopHeaders() []string

GetHopByHopHeaders returns a list of hop-by-hop headers. These should be removed when sending proxied responses to the client. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

func ParseURLHost

func ParseURLHost(u *url.URL) (host, port string, err error)

ParseURLHost extracts the hostname (without port) and the port from the supplied URL

Types

type ContentRange

type ContentRange struct {
	Start, Length, ObjSize uint64
}

ContentRange specifies the byte range to be sent to the client.

func GetResponseRange

func GetResponseRange(code int, headers http.Header) (*ContentRange, error)

GetResponseRange returns the expected response range according to either the Content-Length header for full responses or the Content-Range header for partial ones. If not enough information is present, it returns an error

func ParseResponseContentRange

func ParseResponseContentRange(cr string) (*ContentRange, error)

ParseResponseContentRange parses a "Content-Range" header string. It only implements a subset of RFC 7233 - asterisks (unknown complete-length or unsatisfied-range) are treated as an error.

type FlexibleResponseWriter

type FlexibleResponseWriter struct {
	Code       int         // the HTTP response code from WriteHeader
	Headers    http.Header // the HTTP response headers
	BodyWriter io.WriteCloser
	// contains filtered or unexported fields
}

FlexibleResponseWriter is an implementation of http.ResponseWriter that calls a hook function before accepting writes. The hook function's job is to inspect the current state and determine where the body should be written.

func NewFlexibleResponseWriter

func NewFlexibleResponseWriter(hook func(*FlexibleResponseWriter)) *FlexibleResponseWriter

NewFlexibleResponseWriter returns an initialized FlexibleResponseWriter.

func (*FlexibleResponseWriter) Close

func (frw *FlexibleResponseWriter) Close() error

Close closes the internal bodyWriter

func (*FlexibleResponseWriter) Header

func (frw *FlexibleResponseWriter) Header() http.Header

Header returns the response headers.

func (*FlexibleResponseWriter) ReadFrom added in v0.1.5

func (frw *FlexibleResponseWriter) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom uses io.Copy with the BoduWriter if available after writing headers and checking that the writer is set

func (*FlexibleResponseWriter) Write

func (frw *FlexibleResponseWriter) Write(buf []byte) (int, error)

Write checks if a writer is initialized. If there is a body writer, it passes the arguments to it. If there isn't one, it fails.

func (*FlexibleResponseWriter) WriteHeader

func (frw *FlexibleResponseWriter) WriteHeader(code int)

WriteHeader sets rw.Code and calls the hook function.

type Range

type Range struct {
	Start, Length uint64
}

Range specifies the byte range from a client request.

func ParseRequestRange

func ParseRequestRange(s string, size uint64) ([]Range, error)

ParseRequestRange parses a client "Range" header string as per RFC 7233.

func (Range) ContentRange

func (r Range) ContentRange(size uint64) string

ContentRange returns Range as string appropriate for usage as value of Content-Range header.

func (Range) Range

func (r Range) Range() string

Range returns Range as string appropriate for usage as value of Range header.

Jump to

Keyboard shortcuts

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