httplib

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 31 Imported by: 13

Documentation

Index

Constants

View Source
const (
	// AuthBasic is username / password basic auth
	AuthBasic = "Basic"
	// AuthBearer is bearer tokens auth
	AuthBearer = "Bearer"
	// AccessTokenQueryParam URI query parameter
	AccessTokenQueryParam = "access_token"
)

Variables

Methods contains all HTTP methods

Functions

func ClearSessionHeaders

func ClearSessionHeaders(w http.ResponseWriter) error

ClearSessionHeaders removes all server side cookies

func Dial

func Dial(ctx context.Context, network, addr string) (net.Conn, error)

Dial dials the specified address and returns a new connection

func DialFromEnviron

func DialFromEnviron(dnsAddr string) func(ctx context.Context, network, addr string) (net.Conn, error)

DialFromEnviron determines if the specified address should be resolved using local resolver prior to dialing

func DialWithLocalResolver

func DialWithLocalResolver(ctx context.Context, dnsAddr, network, addr string) (net.Conn, error)

DialWithLocalResolver resolves the specified address using the local resolver before dialing. Returns a new connection on success.

func DialWithServiceResolver

func DialWithServiceResolver(ctx context.Context, network, host, port string) (conn net.Conn, err error)

DialWithServiceResolver resolves the host as a kubernetes service using its cluster IP

func GRPCHandlerFunc

func GRPCHandlerFunc(grpcHandler, httpHandler http.Handler) http.Handler

GRPCHandlerFunc returns an http.Handler that delegates to grpcHandler on incoming gRPC connections or httpHandler otherwise

func GetClient

func GetClient(insecure bool, options ...ClientOption) *http.Client

GetClient returns secure or insecure client based on settings

func GetClusterKubeClient

func GetClusterKubeClient(dnsAddr string, options ...KubeConfigOption) (*kubernetes.Clientset, *rest.Config, error)

GetClusterKubeClient returns a Kubernetes client that uses scheduler certificate for authentication

func GetGRPCPlanetClient

func GetGRPCPlanetClient(ctx context.Context) (client.Client, error)

GetGRPCPlanetClient a grpc client connection to the local planet agent.

func GetPlanetClient

func GetPlanetClient(options ...ClientOption) (*http.Client, error)

func GetRemoteClient

func GetRemoteClient(remoteSite rt.RemoteSite, remoteURL *url.URL) *http.Client

GetRemoteClient returns http.Client for the remote site

func GetUnprivilegedKubeClient

func GetUnprivilegedKubeClient(dnsAddr string, options ...KubeConfigOption) (*kubernetes.Clientset, *rest.Config, error)

GetUnprivilegedKubeClient returns a Kubernetes client that uses kubelet certificate for authentication

func InGravity

func InGravity(dnsAddress string) error

InGravity returns nil if the method was invoked inside running Gravity cluster.

func InKubernetes

func InKubernetes() bool

InKubernetes returns true if the current context is inside a Kubernetes cluster.

func Message

func Message(msg string) interface{}

Message returns structured message response

func NewClient

func NewClient(options ...ClientOption) *http.Client

NewClient creates a new HTTP client with the specified list of configuration options

func OK

func OK() interface{}

OK returns structured OK response

func SetGrafanaHeaders

func SetGrafanaHeaders(h http.Header, clusterName string, path string, expired bool)

SetGrafanaHeaders adds a cookie that holds information about current cluster

func SetupWebsocketClient

func SetupWebsocketClient(ctx context.Context, c *roundtrip.Client, endpoint string, localDialer Dialer) (io.ReadCloser, error)

SetupWebsocketClient sets up roundtrip client to dial web socket method

func VerifySameOrigin

func VerifySameOrigin(r *http.Request) error

VerifySameOrigin checks the HTTP request header values against CSRF attacks There are two steps to check: 1. Determining where the origin the request is coming from (source origin) 2. Determining where the origin the request is going to (target origin) https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#Verifying_Same_Origin_with_Standard_Headers

func WebsocketClientForURL

func WebsocketClientForURL(URL string, headers http.Header) (*websocket.Conn, error)

WebsocketClientForURL creates a new websocket client for the specified url using provided headers

func WriteError

func WriteError(w http.ResponseWriter, err error, hdr http.Header)

WriteError serializes the given error into the provided response writer. The amount of serialized information depends on the HTTP headers.

Types

type Addr

type Addr struct {
	// Addr is network address
	Addr string
	// Net is address type
	Net string
}

Addr helps us to implement net.Addr interface

func (*Addr) Network

func (a *Addr) Network() string

Network should return network type, e.g. tcp

func (*Addr) String

func (a *Addr) String() string

String should return address

type AuthCreds

type AuthCreds struct {
	// Type is auth HTTP auth type (either Bearer or Basic)
	Type string
	// Username is HTTP username
	Username string
	// Password holds password in case of Basic auth, http token otherwize
	Password string
}

AuthCreds hold authentication credentials for the given HTTP request

func ParseAuthHeaders

func ParseAuthHeaders(r *http.Request) (*AuthCreds, error)

ParseAuthHeaders parses authentication headers from HTTP request it currently detects Bearer and Basic auth types

func (*AuthCreds) IsToken

func (a *AuthCreds) IsToken() bool

type Authenticator

type Authenticator func(w http.ResponseWriter, r *http.Request, checkBearerToken bool) (*teleweb.SessionContext, error)

type ClientOption

type ClientOption func(*httpClient)

ClientOption sets custom HTTP client option

func WithCA

func WithCA(cert []byte) ClientOption

WithCA to use a custom certificate authority for server validation

func WithClientCert

func WithClientCert(cert tls.Certificate) ClientOption

WithClientCert sets a certificate for mTLS client authentication

func WithDialTimeout

func WithDialTimeout(t time.Duration) ClientOption

WithDialTimeout sets dial timeout

func WithIdleConnTimeout

func WithIdleConnTimeout(timeout time.Duration) ClientOption

WithIdleConnTimeout overrides the transport connection idle timeout

func WithInsecure

func WithInsecure() ClientOption

WithInsecure sets insecure TLS config

func WithLocalResolver

func WithLocalResolver(dnsAddr string) ClientOption

WithLocalResolver sets up client to use local DNS resolver

func WithTLSClientConfig

func WithTLSClientConfig(tlsConfig *tls.Config) ClientOption

WithTLSClientConfig sets TLS client configuration.

func WithTimeout

func WithTimeout(t time.Duration) ClientOption

WithTimeout sets timeout

type Dialer

type Dialer func(ctx context.Context, network, addr string) (net.Conn, error)

func LocalResolverDialer

func LocalResolverDialer(dnsAddr string) Dialer

LocalResolverDialer returns Dialer that uses the specified DNS server

type KubeConfigOption

type KubeConfigOption func(*rest.Config)

KubeConfigOption represents a functional argument type that allows to modify Kubernetes client configuration before creating it.

func WithHost

func WithHost(host string) KubeConfigOption

WithHost sets host in the Kubernetes client config.

type WebSocketReader

type WebSocketReader struct {
	Reader io.ReadCloser
}

WebSocketReader is a web socket handler, ignores all input and streams everything it read from reader to the web socket connection

func (*WebSocketReader) Close

func (w *WebSocketReader) Close() error

func (*WebSocketReader) Handler

func (w *WebSocketReader) Handler() http.Handler

Jump to

Keyboard shortcuts

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