Documentation ¶
Overview ¶
Package httplib implements common utility functions for writing classic HTTP handlers
Package httplib implements common utility functions for writing classic HTTP handlers
Index ¶
- func ConvertResponse(re *roundtrip.Response, err error) (*roundtrip.Response, error)
- func MakeHandler(fn HandlerFunc) httprouter.Handle
- func MakeHandlerWithErrorWriter(fn HandlerFunc, errWriter ErrorWriter) httprouter.Handle
- func MakeSecurityHeaderHandler(h http.Handler) http.Handler
- func MakeStdHandlerWithErrorWriter(fn StdHandlerFunc, errWriter ErrorWriter) http.HandlerFunc
- func MakeTracingHandler(h http.Handler, component string) http.Handler
- func MakeTracingMiddleware(component string) func(http.Handler) http.Handler
- func OriginLocalRedirectURI(redirectURL string) (string, error)
- func ParseBool(q url.Values, name string) (bool, bool, error)
- func ReadJSON(r *http.Request, val interface{}) error
- func RewritePaths(next http.Handler, rewrites ...RewritePair) http.Handler
- func SetAppLaunchContentSecurityPolicy(h http.Header, applicationURL string)
- func SetCacheHeaders(h http.Header, maxAge time.Duration)
- func SetDefaultSecurityHeaders(h http.Header)
- func SetIndexContentSecurityPolicy(h http.Header, cfg proto.Features, urlPath string)
- func SetNoCacheHeaders(h http.Header)
- func SetRedirectPageContentSecurityPolicy(h http.Header, scriptSrc string)
- func SetScriptHeaders(h http.Header)
- func SetWebConfigHeaders(h http.Header)
- func WithCSRFProtection(fn HandlerFunc) httprouter.Handle
- func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn
- type ErrorWriter
- type HandlerFunc
- type ResponseStatusRecorder
- type RewritePair
- type StdHandlerFunc
- type TLSCreds
- func (c *TLSCreds) ClientHandshake(ctx context.Context, authority string, rawConn net.Conn) (_ net.Conn, _ credentials.AuthInfo, err error)
- func (c *TLSCreds) Clone() credentials.TransportCredentials
- func (c TLSCreds) Info() credentials.ProtocolInfo
- func (c *TLSCreds) OverrideServerName(serverNameOverride string) error
- func (c *TLSCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertResponse ¶
ConvertResponse converts http error to internal error type based on HTTP response code and HTTP body contents
func MakeHandler ¶
func MakeHandler(fn HandlerFunc) httprouter.Handle
MakeHandler returns a new httprouter.Handle func from a handler func
func MakeHandlerWithErrorWriter ¶
func MakeHandlerWithErrorWriter(fn HandlerFunc, errWriter ErrorWriter) httprouter.Handle
MakeHandlerWithErrorWriter returns a httprouter.Handle from the HandlerFunc, and sends all errors to ErrorWriter.
func MakeSecurityHeaderHandler ¶
MakeSecurityHeaderHandler returns a new httprouter.Handle func that wraps the provided handler func with one that will ensure the headers from SetDefaultSecurityHeaders are applied.
func MakeStdHandlerWithErrorWriter ¶
func MakeStdHandlerWithErrorWriter(fn StdHandlerFunc, errWriter ErrorWriter) http.HandlerFunc
MakeStdHandlerWithErrorWriter returns a http.HandlerFunc from the StdHandlerFunc, and sends all errors to ErrorWriter.
func MakeTracingHandler ¶
MakeTracingHandler returns a new httprouter.Handle func that wraps the provided handler func with one that will add a tracing span for each request.
func MakeTracingMiddleware ¶
MakeTracingMiddleware returns an HTTP middleware that makes tracing handlers.
func OriginLocalRedirectURI ¶
OriginLocalRedirectURI will take an incoming URL including optionally the host and scheme and return the URI associated with the URL. Additionally, it will ensure that the URI does not include any techniques potentially used to redirect to a different origin.
func RewritePaths ¶
func RewritePaths(next http.Handler, rewrites ...RewritePair) http.Handler
RewritePaths creates a middleware that rewrites paths in incoming request
func SetAppLaunchContentSecurityPolicy ¶
DELETE IN 17.0: Kept for legacy app access.
SetAppLaunchContentSecurityPolicy sets the Content-Security-Policy header for /web/launch
func SetCacheHeaders ¶
SetCacheHeaders tells proxies and browsers to cache the content
func SetDefaultSecurityHeaders ¶
SetDefaultSecurityHeaders adds headers that should generally be considered safe defaults. It is expected that all responses should be able to add these headers without negative impact.
func SetIndexContentSecurityPolicy ¶
SetIndexContentSecurityPolicy sets the Content-Security-Policy header for main index.html page
func SetNoCacheHeaders ¶
SetNoCacheHeaders tells proxies and browsers do not cache the content
func SetScriptHeaders ¶
SetScriptHeaders sets headers for the teleport install script
func SetWebConfigHeaders ¶
SetWebConfigHeaders sets headers for webConfig.js
func WithCSRFProtection ¶
func WithCSRFProtection(fn HandlerFunc) httprouter.Handle
WithCSRFProtection ensures that request to unauthenticated API is checked against CSRF attacks
func WrapSyscallConn ¶
WrapSyscallConn tries to wrap rawConn and newConn into a net.Conn that implements syscall.Conn. rawConn will be used to support syscall, and newConn will be used for read/write.
This function returns newConn if rawConn doesn't implement syscall.Conn.
Types ¶
type ErrorWriter ¶
type ErrorWriter func(w http.ResponseWriter, err error)
ErrorWriter is a function responsible for writing the error into response body.
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error)
HandlerFunc specifies HTTP handler function that returns error
type ResponseStatusRecorder ¶
type ResponseStatusRecorder struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseStatusRecorder is an http.ResponseWriter that records the response status code.
func NewResponseStatusRecorder ¶
func NewResponseStatusRecorder(w http.ResponseWriter) *ResponseStatusRecorder
NewResponseStatusRecorder makes and returns a ResponseStatusRecorder.
func (*ResponseStatusRecorder) Flush ¶
func (r *ResponseStatusRecorder) Flush()
Flush optionally flushes the inner ResponseWriter if it supports that. Otherwise, Flush is a noop.
Flush is optionally used by github.com/gravitational/oxy/forward to flush pending data on streaming HTTP responses (like streaming pod logs).
Without this, oxy/forward will handle streaming responses by accumulating ~32kb of response in a buffer before flushing it.
func (*ResponseStatusRecorder) Hijack ¶
func (r *ResponseStatusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements the http.Hijacker interface.
func (*ResponseStatusRecorder) Status ¶
func (r *ResponseStatusRecorder) Status() int
Status returns the recorded status after WriteHeader is called, or StatusOK if WriteHeader hasn't been called explicitly.
func (*ResponseStatusRecorder) WriteHeader ¶
func (r *ResponseStatusRecorder) WriteHeader(status int)
WriteHeader sends an HTTP response header with the provided status code and save the status code in the recorder.
type RewritePair ¶
type RewritePair struct { // Expr is matching expression Expr *regexp.Regexp // Replacement is replacement Replacement string }
RewritePair is a rewrite expression
func Rewrite ¶
func Rewrite(in, out string) RewritePair
Rewrite creates a rewrite pair, panics if in epxression is not a valid regular expressoin
type StdHandlerFunc ¶
type StdHandlerFunc func(w http.ResponseWriter, r *http.Request) (interface{}, error)
StdHandlerFunc specifies HTTP handler function that returns error
type TLSCreds ¶
TLSCreds is the credentials required for authenticating a connection using TLS.
func (*TLSCreds) ClientHandshake ¶
func (c *TLSCreds) ClientHandshake(ctx context.Context, authority string, rawConn net.Conn) (_ net.Conn, _ credentials.AuthInfo, err error)
ClientHandshake callback is called to perform client handshake on the tls conn
func (*TLSCreds) Clone ¶
func (c *TLSCreds) Clone() credentials.TransportCredentials
Clone clones transport credentials
func (*TLSCreds) OverrideServerName ¶
OverrideServerName overrides server name in the TLS config
func (*TLSCreds) ServerHandshake ¶
ServerHandshake callback is called to perform server TLS handshake this wrapper makes sure that the connection is already tls and handshake has been performed