Documentation ¶
Index ¶
- Variables
- func ContentType(content io.Reader, name string) (ctype string, bufferedContent io.Reader, err error)
- func DoesRequestSatisfyTlsTermination(r *http.Request, whitelistedPaths []string, allowedTLSCIDRs []string) error
- func Get(url string) (resp *http.Response, err error)
- func GetProxySchemeAndHost(r *http.Request, allowForwarded bool) (scheme, host string)
- func Head(url string) (resp *http.Response, err error)
- func NewClient(u string) (*http.Client, error)
- func Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
- func PostForm(url string, data url.Values) (resp *http.Response, err error)
- func Recover(writer io.Writer, req *http.Request, ...) interface{}
- func RecoveryServerInterceptor(next http.Handler, out io.Writer, ...) http.Handler
- func RejectInsecureServerInterceptor(next http.Handler, opts ...RejectInsecureOption) *rejectInsecure
- func ReplacePath(path string, h http.Handler) http.Handler
- func RequestIDFromContext(ctx context.Context) string
- func ResolveProxyUrl(u *url.URL, r *http.Request, allowForwarded bool) *url.URL
- func ServeContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, ...)
- func XRequestIdServerInterceptor(next http.Handler, keys ...interface{}) http.Handler
- type Client
- type EmptyRejectInsecureOption
- type RejectInsecureOption
- func RejectInsecureWithAllowedTlsCidrs(allowedTLSCIDRs []string) RejectInsecureOption
- func RejectInsecureWithErrorLog(l *log.Logger) RejectInsecureOption
- func RejectInsecureWithForceHttp(forceHttp bool) RejectInsecureOption
- func RejectInsecureWithWhitelistedPaths(whitelistedPaths []string) RejectInsecureOption
- type RejectInsecureOptionFunc
- type RoundTripFunc
- type RoundTripHandler
- type Transport
- func (t *Transport) Abort()
- func (t *Transport) CancelRequest(req *http.Request)
- func (t *Transport) IsAborted() bool
- func (t *Transport) Next(req *http.Request) (resp *http.Response, err error)
- func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)
- func (t *Transport) Use(h ...RoundTripHandler) *Transport
Constants ¶
This section is empty.
Variables ¶
var DefaultXRequestIDKey = "X-Request-ID"
DefaultXRequestIDKey is metadata key name for request ID
var Methods = []string{ http.MethodOptions, http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace, }
Functions ¶
func ContentType ¶
func DoesRequestSatisfyTlsTermination ¶
func DoesRequestSatisfyTlsTermination(r *http.Request, whitelistedPaths []string, allowedTLSCIDRs []string) error
DoesRequestSatisfyTlsTermination returns whether the request fulfills tls's constraints, https, path matches any whitelisted paths or ip inclued by any cidr whitelistedPath is http path that does not need to be checked allowedTLSCIDR is the network includes ip.
func GetProxySchemeAndHost ¶
GetProxySchemeAndHost extracts the host and used protocol (either HTTP or HTTPS) from the given request. If `allowForwarded` is set, the X-Forwarded-Host, X-Forwarded-Proto and Forwarded headers will also be checked to support proxies.
func Recover ¶
func Recover(writer io.Writer, req *http.Request, recoverHandler func(err interface{}) interface{}) interface{}
Recover and dump HTTP request if broken pipe
func RecoveryServerInterceptor ¶
func RecoveryServerInterceptor(next http.Handler, out io.Writer, f func(w http.ResponseWriter, r *http.Request, err interface{})) http.Handler
RecoveryServerInterceptor returns a new server interceptors with recovery from panic. affect as recover{f()}; next()
func RejectInsecureServerInterceptor ¶
func RejectInsecureServerInterceptor(next http.Handler, opts ...RejectInsecureOption) *rejectInsecure
RejectInsecureServerInterceptor returns a new server interceptor with tls check. reject the request fulfills tls's constraints,
func ReplacePath ¶
StripPrefix returns a handler that serves HTTP requests by removing the given prefix from the request URL's Path and invoking the handler h. StripPrefix handles a request for a path that doesn't begin with prefix by replying with an HTTP 404 not found error.
func RequestIDFromContext ¶
func ResolveProxyUrl ¶
func ServeContent ¶
func ServeContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, content io.Reader, size int64)
ServeContent replies to the request using the content in the provided Reader. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.
If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.
If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.
If the content's Seek method work: ServeContent uses a seek to the end of the content to determine its size, and the param size is ignored. The same as http.ServeFile If the content's Seek method doesn't work: ServeContent uses the param size to generate a onlySizeSeekable as a pseudo io.ReadSeeker. If size < 0, use chunk or connection close instead
If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.
Note that *os.File implements the io.ReadSeeker interface.
Types ¶
type EmptyRejectInsecureOption ¶
type EmptyRejectInsecureOption struct{}
EmptyRejectInsecureOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type RejectInsecureOption ¶
type RejectInsecureOption interface {
// contains filtered or unexported methods
}
A RejectInsecureOption sets options.
func RejectInsecureWithAllowedTlsCidrs ¶
func RejectInsecureWithAllowedTlsCidrs(allowedTLSCIDRs []string) RejectInsecureOption
RejectInsecureWithAllowedTlsCidrs specifies whether to allow any request which client or proxy's ip included a cidr is a CIDR notation IP address and prefix length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
func RejectInsecureWithErrorLog ¶
func RejectInsecureWithErrorLog(l *log.Logger) RejectInsecureOption
RejectInsecureWithErrorLog specifies an optional logger for errors
func RejectInsecureWithForceHttp ¶
func RejectInsecureWithForceHttp(forceHttp bool) RejectInsecureOption
RejectInsecureWithForceHttp specifies whether to allow any request, as a shortcut circuit
func RejectInsecureWithWhitelistedPaths ¶
func RejectInsecureWithWhitelistedPaths(whitelistedPaths []string) RejectInsecureOption
RejectInsecureWithWhitelistedPaths specifies whether to allow any request which http path matches
type RejectInsecureOptionFunc ¶
type RejectInsecureOptionFunc func(*rejectInsecure)
RejectInsecureOptionFunc wraps a function that modifies rejectInsecure into an implementation of the RejectInsecureOption interface.
type RoundTripFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
type RoundTripHandler ¶
func RecoveryClientInterceptor ¶
func RecoveryClientInterceptor(next RoundTripHandler, out io.Writer, f func(resp *http.Response, req *http.Request, err interface{})) RoundTripHandler
RecoveryClientInterceptor returns a new client interceptors with recovery from panic. affect as recover{f()}; next()
func XRequestIdClientInterceptor ¶
func XRequestIdClientInterceptor(next RoundTripHandler, keys ...interface{}) RoundTripHandler
XRequestIdClientInterceptor returns a new client interceptors with x-request-id in context and request's Header.
type Transport ¶
type Transport struct { // Base is the base RoundTripper used to make HTTP requests. // If nil, http.DefaultTransport is used. Base http.RoundTripper // contains filtered or unexported fields }
Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests, wrapping a base RoundTripper and adding an Authorization header with a token from the supplied Sources.
Transport is a low-level mechanism. Most code will use the higher-level Config.Client method instead.
func (*Transport) Abort ¶
func (t *Transport) Abort()
Abort prevents pending handlers from being called. Note that this will not stop the current handler. Let's say you have an authorization middleware that validates that the current request is authorized. If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers for this request are not called.
func (*Transport) CancelRequest ¶
CancelRequest cancels an in-flight request by closing its connection.
func (*Transport) Next ¶
Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler. See example in GitHub.
func (*Transport) RoundTrip ¶
RoundTrip authorizes and authenticates the request with an access token. If no token exists or token is expired, tries to refresh/fetch a new token.
func (*Transport) Use ¶
func (t *Transport) Use(h ...RoundTripHandler) *Transport
Use adds middleware handlers to the transport.
Source Files ¶
- client.go
- content_range.go
- fs.go
- interceptors.recover.client.go
- interceptors.recover.go
- interceptors.recover.server.go
- interceptors.reject.server.go
- interceptors.x-request-id.client.go
- interceptors.x-request-id.go
- interceptors.x-request-id.server.go
- method.go
- proxy.go
- range.go
- reject_insecure.option.go
- rejectinsecure_options.go
- server.go
- transport.go
- transport.handler.go