httpserver

package
v1.102.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 27 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAuthFlag added in v1.86.0

func CheckAuthFlag(w http.ResponseWriter, r *http.Request, expectedKey *flagutil.Password) bool

CheckAuthFlag checks whether the given authKey is set and valid

Falls back to checkBasicAuth if authKey is not set

func CheckBasicAuth added in v1.86.0

func CheckBasicAuth(w http.ResponseWriter, r *http.Request) bool

CheckBasicAuth validates credentials provided in request if httpAuth.* flags are set returns true if credentials are valid or httpAuth.* flags are not set

func EnableCORS

func EnableCORS(w http.ResponseWriter, _ *http.Request)

EnableCORS enables https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS on the response.

func Errorf

func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...any)

Errorf writes formatted error message to w and to logger.

func GetPathPrefix added in v1.50.0

func GetPathPrefix() string

GetPathPrefix - returns http server path prefix.

func GetQuotedRemoteAddr added in v1.39.3

func GetQuotedRemoteAddr(r *http.Request) string

GetQuotedRemoteAddr returns quoted remote address.

func GetRequestURI added in v1.63.0

func GetRequestURI(r *http.Request) string

GetRequestURI returns requestURI for r.

func IsTLS added in v1.34.6

func IsTLS(idx int) bool

IsTLS indicates is tls enabled or not for -httpListenAddr at the given idx.

func LogError added in v1.87.0

func LogError(req *http.Request, errStr string)

LogError logs the errStr with the context from req.

func Redirect added in v1.82.0

func Redirect(w http.ResponseWriter, url string)

Redirect redirects to the given url.

func Serve

func Serve(addrs []string, useProxyProtocol *flagutil.ArrayBool, rh RequestHandler)

Serve starts an http server on the given addrs with the given optional rh.

By default all the responses are transparently compressed, since egress traffic is usually expensive.

The compression can be disabled by specifying -http.disableResponseCompression command-line flag.

If useProxyProtocol is set to true for the corresponding addr, then the incoming connections are accepted via proxy protocol. See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt

func Stop

func Stop(addrs []string) error

Stop stops the http server on the given addrs, which has been started via Serve func.

func WriteAPIHelp added in v1.59.0

func WriteAPIHelp(w io.Writer, pathList [][2]string)

WriteAPIHelp writes pathList to w in HTML format.

Types

type ErrorWithStatusCode added in v1.27.0

type ErrorWithStatusCode struct {
	Err        error
	StatusCode int
}

ErrorWithStatusCode is error with HTTP status code.

The given StatusCode is sent to client when the error is passed to Errorf.

func (*ErrorWithStatusCode) Error added in v1.27.0

func (e *ErrorWithStatusCode) Error() string

Error implements error interface.

func (*ErrorWithStatusCode) Unwrap added in v1.37.4

func (e *ErrorWithStatusCode) Unwrap() error

Unwrap returns e.Err.

This is used by standard errors package. See https://golang.org/pkg/errors

type Path added in v1.64.0

type Path struct {
	Prefix    string
	AuthToken string
	Suffix    string
}

Path contains the following path structure: /{prefix}/{authToken}/{suffix}

It is compatible with SaaS version.

func ParsePath added in v1.64.0

func ParsePath(path string) (*Path, error)

ParsePath parses the given path.

type RequestHandler

type RequestHandler func(w http.ResponseWriter, r *http.Request) bool

RequestHandler must serve the given request r and write response to w.

RequestHandler must return true if the request has been served (successfully or not).

RequestHandler must return false if it cannot serve the given request. In such cases the caller must serve the request.

Jump to

Keyboard shortcuts

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