httplib

package
v1.2.3-fred.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 22 Imported by: 136

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertResponse

func ConvertResponse(re *roundtrip.Response, err error) (*roundtrip.Response, error)

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 MakeStdHandler

func MakeStdHandler(fn StdHandlerFunc) http.HandlerFunc

MakeStdHandler returns a new http.Handle func from http.HandlerFunc

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

func MakeTracingHandler(h http.Handler, component string) http.Handler

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 ParseBool

func ParseBool(q url.Values, name string) (bool, bool, error)

ParseBool will parse boolean variable from url query returns value, ok, error

func ReadJSON

func ReadJSON(r *http.Request, val interface{}) error

ReadJSON reads HTTP json request and unmarshals it into passed interface{} obj

func RewritePaths

func RewritePaths(next http.Handler, rewrites ...RewritePair) http.Handler

RewritePaths creates a middleware that rewrites paths in incoming request

func SafeRedirect

func SafeRedirect(w http.ResponseWriter, r *http.Request, redirectURL string) error

SafeRedirect performs a relative redirect to the URI part of the provided redirect URL

func SetIndexHTMLHeaders

func SetIndexHTMLHeaders(h http.Header)

SetIndexHTMLHeaders sets security header flags for main index.html page

func SetNoCacheHeaders

func SetNoCacheHeaders(h http.Header)

SetNoCacheHeaders tells proxies and browsers do not cache the content

func SetNoSniff

func SetNoSniff(h http.Header)

SetNoSniff sets X-Content-Type-Options flag

func SetSameOriginIFrame

func SetSameOriginIFrame(h http.Header)

SetSameOriginIFrame sets X-Frame-Options flag

func SetScriptHeaders

func SetScriptHeaders(h http.Header)

SetScriptHeaders sets headers for the teleport install script

func SetStaticFileHeaders

func SetStaticFileHeaders(h http.Header)

SetStaticFileHeaders sets security header flags for static non-html resources

func SetWebConfigHeaders

func SetWebConfigHeaders(h http.Header)

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

func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn

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 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

type TLSCreds struct {
	// TLS configuration
	Config *tls.Config
}

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

Clone clones transport credentials

func (TLSCreds) Info

Info returns protocol info

func (*TLSCreds) OverrideServerName

func (c *TLSCreds) OverrideServerName(serverNameOverride string) error

OverrideServerName overrides server name in the TLS config

func (*TLSCreds) ServerHandshake

func (c *TLSCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error)

ServerHandshake callback is called to perform server TLS handshake this wrapper makes sure that the connection is already tls and handshake has been performed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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