httputils

package
v0.0.0-...-f4fdb20 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HSTSMiddleware

func HSTSMiddleware(next http.Handler) http.Handler

HSTS middleware

func NewDefaultTransport

func NewDefaultTransport() *http.Transport

NewDefaultTransport constructs an http.Transport with settings that should match http.DefaultTransport. Use this when you want to customize your transport options without modifying the global http.DefaultTransport.

This is copied from the golang source source:

https://github.com/golang/go/blob/5fae09b7386de26db59a1184f62fc7b22ec7667b/src/net/http/transport.go#L42-L53

See also: https://github.com/golang/go/issues/26013

Types

type Client

type Client struct {
	Client *http.Client
	Logger logger.Logger
}

Client is a wrapper around http.Client that adds some convenience methods for making requests and handling responses.

func NewClient

func NewClient(logger logger.Logger) *Client

NewClient returns a new Client with sane defaults.

func NewClientWithTimeout

func NewClientWithTimeout(timeout time.Duration, logger logger.Logger) *Client

NewClientWithTimeout returns a new Client with the specified timeout.

func (*Client) MakeRequest

func (c *Client) MakeRequest(requestMethod, url string, body interface{}) (*http.Response, []byte, error)

MakeRequest sends an HTTP request with the specified request method, URL, and body.

func (*Client) MakeRequestWithHeaders

func (c *Client) MakeRequestWithHeaders(requestMethod, url string, body interface{}, headerKey string, headerValue string) (*http.Response, []byte, error)

type HSTS

type HSTS struct {

	// MaxAge sets the duration that the HSTS is valid for.
	MaxAge time.Duration
	// HostOverride provides a host to the redirection URL in the case that the system is behind a load balancer
	// which doesn't provide the X-Forwarded-Host HTTP header (e.g. an Amazon ELB).
	HostOverride string
	// Decides whether to accept the X-Forwarded-Proto header as proof of SSL.
	AcceptXForwardedProtoHeader bool
	// SendPreloadDirective sets whether the preload directive should be set. The directive allows browsers to
	// confirm that the site should be added to a preload list. (see https://hstspreload.appspot.com/)
	SendPreloadDirective bool
	// contains filtered or unexported fields
}

Add HSTS header to response See: https://github.com/chef/automate/issues/5698

func HSTSHandler

func HSTSHandler(next http.Handler) *HSTS

func (*HSTS) ServeHTTP

func (h *HSTS) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HTTPClient

type HTTPClient interface {
	MakeRequest(requestMethod, url string, body interface{}) (*http.Response, []byte, error)
	MakeRequestWithHeaders(requestMethod, url string, body interface{}, headerkey string, headerValue string) (*http.Response, []byte, error)
}

HTTPClient interface represents an HTTP client.

type MockHTTPClient

type MockHTTPClient struct {
	MakeRequestFunc            func(requestMethod, url string, body interface{}) (*http.Response, []byte, error)
	MakeRequestWithHeadersfunc func(requestMethod, url string, body interface{}, headerkey string, headerValue string) (*http.Response, []byte, error)
}

MockHTTPClient is a mock implementation of HTTPClient.

func (*MockHTTPClient) MakeRequest

func (m *MockHTTPClient) MakeRequest(requestMethod, url string, body interface{}) (*http.Response, []byte, error)

func (*MockHTTPClient) MakeRequestWithHeaders

func (m *MockHTTPClient) MakeRequestWithHeaders(requestMethod, url string, body interface{}, headerkey string, headerValue string) (*http.Response, []byte, error)

Jump to

Keyboard shortcuts

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