handler

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const HttpMethodPurge = "PURGE"

HttpMethodPurge - PURGE method.

View Source
const HttpVersion2 = 2

HttpVersion2 - The value for the HTTP/2 protocol.

View Source
const RequestIDHeader = "X-Go-Proxy-Cache-Request-ID"

RequestIDHeader - HTTP Header to be forwarded to the upstream backend.

Variables

View Source
var DefaultTransportDialTimeout time.Duration = 15 * time.Second

DefaultTransportDialTimeout - Default value used for net.Dialer.Timeout

View Source
var DefaultTransportIdleConnTimeout time.Duration = 90 * time.Second

DefaultTransportIdleConnTimeout - Default value used for http.Transport.IdleConnTimeout.

View Source
var DefaultTransportMaxConnsPerHost int = 1000

DefaultTransportMaxConnsPerHost - Default value used for http.Transport.MaxConnsPerHost.

View Source
var DefaultTransportMaxIdleConns int = 1000

DefaultTransportMaxIdleConns - Default value used for http.Transport.MaxIdleConns.

View Source
var DefaultTransportMaxIdleConnsPerHost int = 1000

DefaultTransportMaxIdleConnsPerHost - Default value used for http.Transport.MaxIdleConnsPerHost.

View Source
var SchemeHTTP string = "http"

SchemeHTTP - HTTP scheme.

View Source
var SchemeHTTPS string = "https"

SchemeHTTPS - HTTPS scheme.

View Source
var SchemeWS string = "ws"

SchemeWS - WS scheme.

View Source
var SchemeWSS string = "wss"

SchemeWSS - WSS scheme.

Functions

func ConvertToRequestCallDTO

func ConvertToRequestCallDTO(rc RequestCall) storage.RequestCallDTO

ConvertToRequestCallDTO - Generates a storage DTO containing request, response and cache settings.

func HandleHealthcheck

func HandleHealthcheck(cfg config.Configuration) func(res http.ResponseWriter, req *http.Request)

HandleHealthcheck - Returns healthcheck status.

func HandleRequest

func HandleRequest(res http.ResponseWriter, req *http.Request)

HandleRequest - Handles the entrypoint and directs the traffic to the right handler.

func WrapResponseForGZip added in v1.3.1

func WrapResponseForGZip(res *response.LoggedResponseWriter, req *http.Request)

WrapResponseForGZip - Add HTTP header ETag only on HTTP(S) requests.

Types

type RequestCall

type RequestCall struct {
	ReqID        string
	RequestTime  time.Time
	Response     *response.LoggedResponseWriter
	Request      http.Request
	DomainConfig config.Configuration
}

RequestCall - Main object containing request and response.

func NewRequestCall added in v1.3.1

func NewRequestCall(res http.ResponseWriter, req *http.Request) RequestCall

NewRequestCall - Initialize a RequestCall object starting from incoming Request.

func (RequestCall) GetHostname added in v1.3.1

func (rc RequestCall) GetHostname() string

GetHostname - Returns only the hostname (without port if present).

func (RequestCall) GetLogger added in v1.3.1

func (rc RequestCall) GetLogger() *log.Entry

GetLogger - Get logger instance with RequestID.

func (RequestCall) GetRequestLength added in v1.3.1

func (rc RequestCall) GetRequestLength() int64

GetRequestLength - Return the size of the request

func (RequestCall) GetRequestURL added in v1.3.1

func (rc RequestCall) GetRequestURL() url.URL

GetRequestURL - Returns the valid Request URL (with Scheme and Host).

func (RequestCall) GetResponseWithETag added in v1.3.1

func (rc RequestCall) GetResponseWithETag(ctx context.Context, proxy *httputil.ReverseProxy) (serveNotModified bool)

GetResponseWithETag - Add HTTP header ETag only on HTTP(S) requests.

func (RequestCall) GetScheme

func (rc RequestCall) GetScheme() string

GetScheme - Returns current request scheme. For server requests the URL is parsed from the URI supplied on the Request-Line as stored in RequestURI. For most requests, fields other than Path and RawQuery will be empty. (See RFC 7230, Section 5.3) Ref: https://github.com/golang/go/issues/28940

func (RequestCall) GetUpstreamHost added in v1.3.1

func (rc RequestCall) GetUpstreamHost() string

GetUpstreamHost - Retrieve the real upstream host

func (RequestCall) GetUpstreamURL added in v1.3.1

func (rc RequestCall) GetUpstreamURL() (url.URL, error)

GetUpstreamURL - Get the URL based on the upstream.

func (RequestCall) HandleHTTPRequestAndProxy added in v0.2.0

func (rc RequestCall) HandleHTTPRequestAndProxy(ctx context.Context)

HandleHTTPRequestAndProxy - Handles the HTTP requests and proxies to backend server.

func (RequestCall) HandlePurge

func (rc RequestCall) HandlePurge(ctx context.Context)

HandlePurge - Purges the cache for the requested URI.

func (RequestCall) HandleWSRequestAndProxy added in v0.2.0

func (rc RequestCall) HandleWSRequestAndProxy(ctx context.Context)

HandleWSRequestAndProxy - Handles the websocket requests and proxies to backend server.

func (RequestCall) IsLegitRequest added in v1.3.1

func (rc RequestCall) IsLegitRequest(ctx context.Context, listeningPort string) bool

IsLegitRequest - Check whether a request is bound on the right Host and Port.

func (RequestCall) IsWebSocket added in v0.2.0

func (rc RequestCall) IsWebSocket() bool

IsWebSocket - Checks whether a request is a websocket.

func (RequestCall) ProxyDirector added in v1.3.1

func (rc RequestCall) ProxyDirector(ctx context.Context) func(req *http.Request)

ProxyDirector - Add extra behaviour to request.

func (RequestCall) RedirectToHTTPS

func (rc RequestCall) RedirectToHTTPS(ctx context.Context)

RedirectToHTTPS - Redirects from HTTP to HTTPS.

The redirect target's host is the request's own Host header, which static analysis reads as an attacker-controlled redirect destination (gosec G710, CodeQL go/open-redirect). It is not one: HandleRequest calls initRequestParams before it reaches here, and that rejects with 501 any Host that config.DomainConf does not resolve to a configured domain. Only a host already on the configured allowlist can arrive at this line.

Keep that ordering. If the DomainConf check ever moves after this call, the finding becomes real.

func (RequestCall) SendMethodNotAllowed added in v1.3.1

func (rc RequestCall) SendMethodNotAllowed(ctx context.Context)

SendMethodNotAllowed - Sends a 405 response status code.

func (RequestCall) SendNotImplemented added in v1.3.1

func (rc RequestCall) SendNotImplemented(ctx context.Context)

SendNotImplemented - Sends a 501 response status code.

func (RequestCall) SendNotModifiedResponse added in v1.3.1

func (rc RequestCall) SendNotModifiedResponse(ctx context.Context)

SendNotModifiedResponse - Sends a 304 response status code.

func (RequestCall) SendResponse added in v1.3.1

func (rc RequestCall) SendResponse(ctx context.Context)

SendResponse - Sends the response to the client.

func (RequestCall) SetHSTSHeader added in v1.3.1

func (rc RequestCall) SetHSTSHeader()

SetHSTSHeader - Adds Strict-Transport-Security to HTTPS responses when enabled, mitigating MITM/SSL-stripping downgrade attacks (#11).

Jump to

Keyboard shortcuts

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