http

package
v0.0.0-...-9b16b4d Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusContinue           = 100 // RFC 7231, 6.2.1
	StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2
	StatusProcessing         = 102 // RFC 2518, 10.1
	StatusEarlyHints         = 103 // RFC 8297

	StatusOK                   = 200 // RFC 7231, 6.3.1
	StatusCreated              = 201 // RFC 7231, 6.3.2
	StatusAccepted             = 202 // RFC 7231, 6.3.3
	StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4
	StatusNoContent            = 204 // RFC 7231, 6.3.5
	StatusResetContent         = 205 // RFC 7231, 6.3.6
	StatusPartialContent       = 206 // RFC 7233, 4.1
	StatusMultiStatus          = 207 // RFC 4918, 11.1
	StatusAlreadyReported      = 208 // RFC 5842, 7.1
	StatusIMUsed               = 226 // RFC 3229, 10.4.1

	StatusMultipleChoices  = 300 // RFC 7231, 6.4.1
	StatusMovedPermanently = 301 // RFC 7231, 6.4.2
	StatusFound            = 302 // RFC 7231, 6.4.3
	StatusSeeOther         = 303 // RFC 7231, 6.4.4
	StatusNotModified      = 304 // RFC 7232, 4.1
	StatusUseProxy         = 305 // RFC 7231, 6.4.5

	StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7
	StatusPermanentRedirect = 308 // RFC 7538, 3

	StatusBadRequest                   = 400 // RFC 7231, 6.5.1
	StatusUnauthorized                 = 401 // RFC 7235, 3.1
	StatusPaymentRequired              = 402 // RFC 7231, 6.5.2
	StatusForbidden                    = 403 // RFC 7231, 6.5.3
	StatusNotFound                     = 404 // RFC 7231, 6.5.4
	StatusMethodNotAllowed             = 405 // RFC 7231, 6.5.5
	StatusNotAcceptable                = 406 // RFC 7231, 6.5.6
	StatusProxyAuthRequired            = 407 // RFC 7235, 3.2
	StatusRequestTimeout               = 408 // RFC 7231, 6.5.7
	StatusConflict                     = 409 // RFC 7231, 6.5.8
	StatusGone                         = 410 // RFC 7231, 6.5.9
	StatusLengthRequired               = 411 // RFC 7231, 6.5.10
	StatusPreconditionFailed           = 412 // RFC 7232, 4.2
	StatusRequestEntityTooLarge        = 413 // RFC 7231, 6.5.11
	StatusRequestURITooLong            = 414 // RFC 7231, 6.5.12
	StatusUnsupportedMediaType         = 415 // RFC 7231, 6.5.13
	StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4
	StatusExpectationFailed            = 417 // RFC 7231, 6.5.14
	StatusTeapot                       = 418 // RFC 7168, 2.3.3
	StatusMisdirectedRequest           = 421 // RFC 7540, 9.1.2
	StatusUnprocessableEntity          = 422 // RFC 4918, 11.2
	StatusLocked                       = 423 // RFC 4918, 11.3
	StatusFailedDependency             = 424 // RFC 4918, 11.4
	StatusTooEarly                     = 425 // RFC 8470, 5.2.
	StatusUpgradeRequired              = 426 // RFC 7231, 6.5.15
	StatusPreconditionRequired         = 428 // RFC 6585, 3
	StatusTooManyRequests              = 429 // RFC 6585, 4
	StatusRequestHeaderFieldsTooLarge  = 431 // RFC 6585, 5
	StatusUnavailableForLegalReasons   = 451 // RFC 7725, 3

	StatusInternalServerError           = 500 // RFC 7231, 6.6.1
	StatusNotImplemented                = 501 // RFC 7231, 6.6.2
	StatusBadGateway                    = 502 // RFC 7231, 6.6.3
	StatusServiceUnavailable            = 503 // RFC 7231, 6.6.4
	StatusGatewayTimeout                = 504 // RFC 7231, 6.6.5
	StatusHTTPVersionNotSupported       = 505 // RFC 7231, 6.6.6
	StatusVariantAlsoNegotiates         = 506 // RFC 2295, 8.1
	StatusInsufficientStorage           = 507 // RFC 4918, 11.5
	StatusLoopDetected                  = 508 // RFC 5842, 7.2
	StatusNotExtended                   = 510 // RFC 2774, 7
	StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
)

HTTP status codes as registered with IANA. See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

View Source
const PrefixNg = "/ng-cgi"

Variables

View Source
var (
	// DefaultUpgrader specifies the parameters for upgrading an HTTP
	// connection to a WebSocket connection.
	DefaultUpgrader = &websocket.Upgrader{
		ReadBufferSize:  1024,
		WriteBufferSize: 1024,
	}

	// DefaultDialer is a dialer with all fields set to the default zero values.
	DefaultDialer = websocket.DefaultDialer
)
View Source
var HttpsDialer = httpsDialer{}
View Source
var Redirect2TLS = redirectTLS{}

Functions

func GetRootDomain

func GetRootDomain(host string) string

func IsDoubleTailDomainSuffix

func IsDoubleTailDomainSuffix(domain string) bool

func NewHTTPProxier

func NewHTTPProxier(allowedhosts []string) *httpproxy

func ProxyHandler

func ProxyHandler(target *url.URL) http.Handler

ProxyHandler returns a new http.Handler interface that reverse proxies the request to the given target.

Types

type Cgi

type Cgi interface {
	CgiPaths() utils.GroupRegexp
	HandleHTTPCgi(*HttpCtx, string) Ret
}

type CgiHandler

type CgiHandler func(*HttpCtx, string) Ret

type CgiStruct

type CgiStruct struct {
	CgiHandler
	CgiPaths utils.GroupRegexp
}

type ContentEncoding

type ContentEncoding uint8
const (
	EncodingRAW ContentEncoding = iota
	EncodingBR
	EncodingGZIP
	EncodingDEFALTE
)

func (ContentEncoding) String

func (c ContentEncoding) String() string

type Forward

type Forward interface {
	HostsForward() utils.GroupRegexp
	HandleHTTPForward(*HttpCtx) Ret
}

type FwdForwardProxy

type FwdForwardProxy struct {
	Proxy *url.URL
}

func (*FwdForwardProxy) HandleHTTPForward

func (f *FwdForwardProxy) HandleHTTPForward(ctx *HttpCtx) Ret

func (*FwdForwardProxy) HostsForward

func (*FwdForwardProxy) HostsForward() utils.GroupRegexp

type HttpCtx

type HttpCtx struct {
	//unsync readonly
	Id uint64

	RemoteIP string

	Req  *http.Request
	Resp *NgResponseWriter
	// contains filtered or unexported fields
}

HttpCtx is the context of a http request It holds the request and response writer

func (*HttpCtx) Close

func (c *HttpCtx) Close()

Close executes the close handles. A HttpCtx must be closed after the request is done. It's usually done by the Midware

func (*HttpCtx) IsClosing

func (c *HttpCtx) IsClosing() <-chan struct{}

func (*HttpCtx) OnClose

func (c *HttpCtx) OnClose(f func(*HttpCtx))

func (*HttpCtx) Redirect

func (c *HttpCtx) Redirect(url string, code int)

Redirect redirects the request to another url

func (*HttpCtx) RemoveCookie

func (ctx *HttpCtx) RemoveCookie(key string) (value string)

RemoveCookie removes a cookie from the request. it modifies the orginal request header.

func (*HttpCtx) SetCookie

func (c *HttpCtx) SetCookie(k *http.Cookie)

func (*HttpCtx) WriteString

func (c *HttpCtx) WriteString(s string)

type HttpHost

type HttpHost struct {
	Id         string
	ServerName utils.GroupRegexp

	Backend string
	// contains filtered or unexported fields
}

type Midware

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

func NewHttpMidware

func NewHttpMidware(sni []string) *Midware

func (*Midware) AddCgis

func (mid *Midware) AddCgis(svcs ...*CgiStruct)

AddCgis adds a list of Cgi to the midware. The CgiPaths is called immediately in this function to get the allowed paths of the Cgi.

func (*Midware) AddForwardServices

func (h *Midware) AddForwardServices(p ...*ServiceStruct)

func (*Midware) AddServices

func (mid *Midware) AddServices(svc ...*ServiceStruct)

func (*Midware) Handle

func (h *Midware) Handle(c *tcp.Conn) tcp.SerRet

func (*Midware) KillRequest

func (HMW *Midware) KillRequest(rid uint64) error

func (*Midware) Process

func (h *Midware) Process(RequestCtx *HttpCtx)

func (*Midware) Report

func (ctl *Midware) Report() map[uint64]interface{}

type NgResponseWriter

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

func (*NgResponseWriter) Close

func (w *NgResponseWriter) Close() error

Close closes the writer. It must be called after the request is done.

func (*NgResponseWriter) Code

func (w *NgResponseWriter) Code() int

func (*NgResponseWriter) ConfrimPage

func (rw *NgResponseWriter) ConfrimPage(code int, url string, msg string)

func (*NgResponseWriter) ErrorPage

func (rw *NgResponseWriter) ErrorPage(code int, err string)

func (*NgResponseWriter) Flush

func (w *NgResponseWriter) Flush()

func (*NgResponseWriter) Header

func (w *NgResponseWriter) Header() http.Header

func (*NgResponseWriter) Hijack

func (w *NgResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*NgResponseWriter) InfoPage

func (rw *NgResponseWriter) InfoPage(code int, info string)

func (*NgResponseWriter) Push

func (w *NgResponseWriter) Push(target string, opts *http.PushOptions) error

func (*NgResponseWriter) RefreshRedirectPage

func (rw *NgResponseWriter) RefreshRedirectPage(code int, url string, msg string, time int)

using http header: Refresh

func (*NgResponseWriter) Write

func (w *NgResponseWriter) Write(b []byte) (byt int, e error)

func (*NgResponseWriter) WriteHeader

func (w *NgResponseWriter) WriteHeader(statusCode int)

type Ret

type Ret bool
const (
	RequestEnd Ret = false
	Continue   Ret = true
)

func EchoVerbose

func EchoVerbose(ctx *HttpCtx) Ret

type Service

type Service interface {
	Hosts() utils.GroupRegexp
	HandleHTTP(*HttpCtx) Ret
}

type ServiceHandler

type ServiceHandler func(*HttpCtx) Ret

type ServiceStruct

type ServiceStruct struct {
	ServiceHandler
	Id    string
	Hosts utils.GroupRegexp
}

type StdForwardProxy

type StdForwardProxy struct{}

func (StdForwardProxy) HandleHTTPForward

func (StdForwardProxy) HandleHTTPForward(ctx *HttpCtx) Ret

func (StdForwardProxy) HostsForward

func (StdForwardProxy) HostsForward() utils.GroupRegexp

type WebsocketProxy

type WebsocketProxy struct {
	// Director, if non-nil, is a function that may copy additional request
	// headers from the incoming WebSocket connection into the output headers
	// which will be forwarded to another server.
	Director func(incoming *http.Request, out http.Header)

	// Backend returns the backend URL which the proxy uses to reverse proxy
	// the incoming WebSocket connection. Request is the initial incoming and
	// unmodified request.
	Backend func(*http.Request) *url.URL

	// Upgrader specifies the parameters for upgrading a incoming HTTP
	// connection to a WebSocket connection. If nil, DefaultUpgrader is used.
	Upgrader *websocket.Upgrader

	//  Dialer contains options for connecting to the backend WebSocket server.
	//  If nil, DefaultDialer is used.
	Dialer *websocket.Dialer
}

WebsocketProxy is an HTTP Handler that takes an incoming WebSocket connection and proxies it to another server.

func NewWSProxy

func NewWSProxy(target *url.URL) *WebsocketProxy

NewWSProxy returns a new Websocket reverse proxy that rewrites the URL's to the scheme, host and base path provider in target.

func (*WebsocketProxy) ServeHTTP

func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler that proxies WebSocket connections.

Jump to

Keyboard shortcuts

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