http

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderSourceName is the custom HTTP header for communicating the name of
	// the sending host.
	HeaderSourceName = "X-STS-SrcName"

	// HeaderKey is the custom HTTP header for communicating the key (if applicable)
	// provided by the target.
	HeaderKey = "X-STS-Key"

	// HeaderMetaLen is the custom HTTP header that houses the JSON-encoded metadata
	// length for a bin.
	HeaderMetaLen = "X-STS-MetaLen"

	// HeaderPartCount is the custom HTTP resopnse header that indicates the number
	// of parts successfully received.
	HeaderPartCount = "X-STS-PartCount"

	// HeaderSep is the custom HTTP header used to indicate the path separator string
	// to be used for parsing paths in request/response data.
	HeaderSep = "X-STS-Sep"

	// HeaderContentType is the standard HTTP header for specifying the payload
	// type.
	HeaderContentType = "Content-Type"

	// HeaderContentEncoding is the standard HTTP header for specifying the payload
	// encoding.
	HeaderContentEncoding = "Content-Encoding"

	// HeaderGzip is the content encoding value for gzip compression.
	HeaderGzip = "gzip"

	// HeaderJSON is the content type value for JSON-encoded payload.
	HeaderJSON = "application/json"
)

Variables

This section is empty.

Functions

func Close

func Close() error

Close gracefully shuts down the DefaultServer.

func GetHostname

func GetHostname(r *http.Request) string

GetHostname uses an http.Request object to determine the name of the sending host. Falls back to the IP address.

func GetJSONReader

func GetJSONReader(data interface{}, compression int) (r io.Reader, err error)

GetJSONReader takes an arbitrary struct and generates a JSON reader with no intermediate buffer. It will also add gzip compression at specified level.

func GetReqReader

func GetReqReader(r *http.Request) (io.ReadCloser, error)

GetReqReader will return the appropriate reader for this request body based on the content type.

func GetRespReader

func GetRespReader(r *http.Response) (io.ReadCloser, error)

GetRespReader will return the appropriate reader for this response body based on the content type.

func ListenAndServe

func ListenAndServe(addr string, tlsConf *tls.Config, handler http.Handler) error

ListenAndServe listens on the TCP network address addr using the DefaultServer. If the handler is nil, http.DefaultServeMux is used.

func LoadTLSConf

func LoadTLSConf(certPath, keyPath, caPath string) (conf *tls.Config, err error)

LoadTLSConf returns a tls.Config reference based on provided paths.

func TLSConf

func TLSConf(cert, key, ca []byte) (conf *tls.Config, err error)

TLSConf returns a tls.Config reference based on provided strings.

Types

type BandwidthLoggingClient

type BandwidthLoggingClient struct {
	*http.Client
	// contains filtered or unexported fields
}

func GetClient

func GetClient(
	tlsConf *tls.Config,
	logInterval time.Duration,
	logPrefix string,
) (client *BandwidthLoggingClient, err error)

GetClient returns a secure http.Client instance pointer based on cert paths.

func (*BandwidthLoggingClient) Stop

func (blc *BandwidthLoggingClient) Stop()

type Client

type Client struct {
	SourceName           string
	TargetHost           string
	TargetPort           int
	TargetPrefix         string
	TargetKey            string
	Compression          int
	Timeout              time.Duration
	TLS                  *tls.Config
	PartialsDecoder      sts.DecodePartials
	BandwidthLogInterval time.Duration
	// contains filtered or unexported fields
}

Client is the main client struct

func (*Client) Destroy

func (h *Client) Destroy()

func (*Client) GetClientConf

func (c *Client) GetClientConf(clientID string) (conf *sts.ClientConf, err error)

GetClientConf to fulfill sts.ClientManager interface

func (*Client) GetClientStatus

func (c *Client) GetClientStatus(
	clientID,
	clientName,
	clientOS string,
) (status sts.ClientStatus, err error)

GetClientStatus to fulfill sts.ClientManager interface

func (*Client) Recover

func (h *Client) Recover() (partials []*sts.Partial, err error)

Recover is of type sts.Recoverer and is responsible for retrieving partial files on the target

func (*Client) RecoverTransmission

func (h *Client) RecoverTransmission(payload sts.Payload) (n int, err error)

RecoverTransmission is of type sts.RecoverTransmission for querying how many parts of a failed transmission were successfully received.

func (*Client) SetClientConfReceived

func (c *Client) SetClientConfReceived(clientID string, when time.Time) error

SetClientConfReceived to fulfill sts.ClientManager interface

func (*Client) SetClientState

func (c *Client) SetClientState(clientID string, state sts.ClientState) (err error)

SetClientState to fulfill sts.ClientManager interface

func (*Client) Transmit

func (h *Client) Transmit(payload sts.Payload) (n int, err error)

Transmit is of type sts.Transmit for sending a payload

func (*Client) Validate

func (h *Client) Validate(sent []sts.Pollable) (polled []sts.Polled, err error)

Validate is of type sts.Validate for confirming or denying validity of transmitted files

type GracefulServer

type GracefulServer struct {
	// contains filtered or unexported fields
}

GracefulServer is net/http compatible graceful server. https://github.com/icub3d/graceful/blob/master/graceful.go

var DefaultServer *GracefulServer

DefaultServer is the default Server used by the functions in this package. It's used as to simplify using the graceful server.

func NewGracefulServer

func NewGracefulServer(srv *http.Server, tlsConf *tls.Config) *GracefulServer

NewGracefulServer turns the given net/http server into a graceful server.

func (*GracefulServer) Close

func (s *GracefulServer) Close() error

Close gracefully shuts down the listener. This should be called when the server should stop listening for new connection and finish any open connections.

func (*GracefulServer) ListenAndServe

func (s *GracefulServer) ListenAndServe() error

ListenAndServe works like net/http.Server.ListenAndServe except that it gracefully shuts down when Close() is called. When that occurs, no new connections will be allowed and existing connections will be allowed to finish. This will not return until all existing connections have closed. Will use provided tls.Config for https if applicable.

func (*GracefulServer) Serve

func (s *GracefulServer) Serve(l net.Listener) error

Serve works like ListenAndServer but using the given listener.

type Internal

type Internal struct {
	Port     int
	Handlers map[string]http.HandlerFunc
}

Internal responds to internal HTTP command requests for altering the behavior of the running executable

func (*Internal) Serve

func (s *Internal) Serve(stop <-chan bool, done chan<- bool)

Serve starts HTTP server.

type Server

type Server struct {
	ServeDir    string
	Host        string
	Port        int
	PathPrefix  string
	TLS         *tls.Config
	Compression int

	GateKeepers       map[string]sts.GateKeeper
	GateKeeperFactory sts.GateKeeperFactory
	DecoderFactory    sts.PayloadDecoderFactory

	IsValid       sts.RequestValidator
	ClientManager sts.ClientManager

	ChanceOfSimulatedFailure float64
	// contains filtered or unexported fields
}

Server responds to client HTTP requests

func (*Server) Serve

func (s *Server) Serve(stop <-chan bool, done chan<- bool)

Serve starts HTTP server.

Jump to

Keyboard shortcuts

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