stdhttp

package module
v0.1.119 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 32 Imported by: 20

README

Additional custom packages

Documentation

Index

Constants

View Source
const (
	RequestOptionGzip                = ".gzip"
	RequestOptionSkipTLSVerification = ".skip-tls-verification"
	RequestOptionBasicAuthUser       = ".user"
	RequestOptionBasicAuthPassword   = ".password"
)

options with names starting with "." are used as internal parameters and are not added to query parameters

View Source
const (
	// ContentTypeHTML --
	ContentTypeHTML = "html"
	// ContentTypeCSS --
	ContentTypeCSS = "css"
	// ContentTypeText --
	ContentTypeText = "text"
	// ContentTypeJSON --
	ContentTypeJSON = "json"
	// ContentTypeIcon --
	ContentTypeIcon = "ico"
	// ContentTypeForm --
	ContentTypeForm = "form"
	// ContentTypeBin --
	ContentTypeBin = "bin"

	// MethodCONNECT --
	MethodCONNECT = "CONNECT"
	// MethodTRACE --
	MethodTRACE = "TRACE"
	// MethodOPTIONS --
	MethodOPTIONS = "OPTIONS"
	// MethodHEAD --
	MethodHEAD = "HEAD"
	// MethodGET --
	MethodGET = "GET"
	// MethodPOST --
	MethodPOST = "POST"
	// MethodPUT --
	MethodPUT = "PUT"
	// MethodPATCH --
	MethodPATCH = "PATCH"
	// MethodDELETE --
	MethodDELETE = "DELETE"

	HTTPheaderHash = "X-Hash" // data hash
)
View Source
const (
	CtxIdentity = ContextKey("identity")
)

Variables

Functions

func AddLogFilterForRequest added in v0.1.8

func AddLogFilterForRequest(exp string, replace string) error

AddLogFilterForRequest --

func AddValueToRequestContext added in v0.1.88

func AddValueToRequestContext(r *http.Request, key any, value any) (newR *http.Request)

AddValueToRequestContext --

func CloneURLvalues

func CloneURLvalues(src url.Values) (dst url.Values)

CloneURLvalues --

func CodeName added in v0.1.118

func CodeName(code int) string

func ConcatLogFilterForRequest added in v0.1.76

func ConcatLogFilterForRequest(f *misc.Replace)

ConcatLogFilterForRequest --

func ContentHeader

func ContentHeader(contentType string) (string, error)

ContentHeader --

func Error

func Error(id uint64, answerSent bool, w http.ResponseWriter, r *http.Request, httpCode int, message string, err error)

Error --

func GetIdentityFromRequestContext added in v0.1.88

func GetIdentityFromRequestContext(r *http.Request) (identity *auth.Identity, err error)

func GetValueFromRequestContext added in v0.1.88

func GetValueFromRequestContext(r *http.Request, key any) (value any)

GetValueFromRequestContext --

func JSONResultWithDataHash added in v0.1.89

func JSONResultWithDataHash(data any, useHash bool, hash string, srcHeaders misc.StringMap) (result []byte, code int, headers misc.StringMap, err error)

JSONResultWithDataHash --

func ReadData

func ReadData(header http.Header, body io.ReadCloser) (bodyBuf *bytes.Buffer, code int, err error)

ReadData --

func ReadRequestBody

func ReadRequestBody(r *http.Request) (bodyBuf *bytes.Buffer, code int, err error)

ReadRequestBody --

func Request

func Request(method string, uri string, timeout time.Duration, opts misc.StringMap, extraHeaders misc.StringMap, data []byte) (*bytes.Buffer, *http.Response, error)

Request --

func RequestEx added in v0.1.12

func RequestEx(method string, uri string, timeout time.Duration, opts url.Values, extraHeaders http.Header, data []byte) (*bytes.Buffer, *http.Response, error)

RequestEx --

func ReturnRefresh

func ReturnRefresh(id uint64, w http.ResponseWriter, r *http.Request, httpCode int, forceTo string, data []byte, err error)

ReturnRefresh --

func SendJSON

func SendJSON(w http.ResponseWriter, r *http.Request, statusCode int, data any)

SendJSON --

func SetLogFilterForRequest added in v0.1.8

func SetLogFilterForRequest(f *misc.Replace)

SetLogFilterForRequest --

func SetMinSizeForGzip added in v0.1.7

func SetMinSizeForGzip(size int)

SetMinSizeForGzip --

func UseGzip added in v0.1.117

func UseGzip(r *http.Request, dataLen int, headers misc.StringMap) bool

func WriteContentHeader

func WriteContentHeader(w http.ResponseWriter, contentType string) error

WriteContentHeader --

func WriteReply

func WriteReply(w http.ResponseWriter, r *http.Request, httpCode int, contentCode string, extraHeaders misc.StringMap, data []byte) (err error)

WriteReply --

Types

type BlackHole

type BlackHole struct {
}

BlackHole -- http.ResponseWriter implementation

func (*BlackHole) Header

func (bh *BlackHole) Header() http.Header

Header --

func (*BlackHole) Write

func (bh *BlackHole) Write(data []byte) (int, error)

Write --

func (*BlackHole) WriteHeader

func (bh *BlackHole) WriteHeader(statusCode int)

WriteHeader --

type ContextKey added in v0.1.88

type ContextKey string

ContextKey --

type ErrorResponse added in v0.1.118

type ErrorResponse struct {
	Message string `json:"error"`
}

type ExtraInfoFunc

type ExtraInfoFunc func() any

ExtraInfoFunc --

type ExtraRootItemFunc

type ExtraRootItemFunc func(prefix string) []string

ExtraRootItemFunc --

type HTTP

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

HTTP --

func NewListener

func NewListener(listenerCfg *config.Listener, handler Handler) (*HTTP, error)

NewListener --

func NewListenerEx added in v0.1.100

func NewListenerEx(listenerCfg *config.Listener, handler HandlerEx) (*HTTP, error)

func (*HTTP) AddAuthEndpoint added in v0.1.67

func (h *HTTP) AddAuthEndpoint(endpoint string, permissions misc.BoolMap)

AddAuthEndpoint --

func (*HTTP) AddAuthHandler added in v0.1.57

func (h *HTTP) AddAuthHandler(ah auth.Handler) (err error)

AddAuthHandler --

func (*HTTP) AddEndpointsInfo

func (h *HTTP) AddEndpointsInfo(list misc.StringMap)

AddEndpointsInfo --

func (*HTTP) AddHandler added in v0.1.67

func (h *HTTP) AddHandler(handler Handler, toHead bool)

AddHandler --

func (*HTTP) AddHandlerEx added in v0.1.100

func (h *HTTP) AddHandlerEx(handler HandlerEx, toHead bool)

AddHandlerEx --

func (*HTTP) CancelPathReplacing added in v0.1.29

func (h *HTTP) CancelPathReplacing(path string)

CancelPathReplacing --

func (*HTTP) Close added in v0.1.96

func (h *HTTP) Close() error

Close --

func (*HTTP) Config added in v0.1.97

func (h *HTTP) Config() *config.Listener

Config --

func (*HTTP) DelEndpointsInfo added in v0.1.108

func (h *HTTP) DelEndpointsInfo(list misc.StringMap)

func (*HTTP) File added in v0.1.25

func (h *HTTP) File(id uint64, prefix string, path string, w http.ResponseWriter, r *http.Request) (processed bool)

File --

func (*HTTP) GetPrefix added in v0.1.110

func (h *HTTP) GetPrefix(path string, r *http.Request) (prefix string, newPath string)

func (*HTTP) GetPrefixFromHeader added in v0.1.111

func (h *HTTP) GetPrefixFromHeader(r *http.Request) (prefix string)

func (*HTTP) IsPathReplaced added in v0.1.29

func (h *HTTP) IsPathReplaced(path string) bool

IsPathReplaced --

func (*HTTP) MenuHighlight

func (h *HTTP) MenuHighlight() (open template.HTML, close template.HTML)

MenuHighlight --

func (*HTTP) RemoveStdPath added in v0.1.29

func (h *HTTP) RemoveStdPath(path string)

RemoveStdPath --

func (*HTTP) ServeHTTP

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

ServeHTTP --

func (*HTTP) SetExtraInfoFunc

func (h *HTTP) SetExtraInfoFunc(f ExtraInfoFunc)

SetExtraInfoFunc --

func (*HTTP) SetName

func (h *HTTP) SetName(name string, description string)

SetName --

func (*HTTP) SetRootItemsFunc

func (h *HTTP) SetRootItemsFunc(f ExtraRootItemFunc)

SetRootItemsFunc --

func (*HTTP) SetStatusFunc added in v0.1.47

func (h *HTTP) SetStatusFunc(f StatusFunc, paramsInfo string)

SetStatusFunc --

func (*HTTP) Start

func (h *HTTP) Start() error

Start --

func (*HTTP) Stop

func (h *HTTP) Stop() error

Stop --

type Handler

type Handler interface {
	Handler(id uint64, prefix string, path string, w http.ResponseWriter, r *http.Request) (processed bool)
}

Handler --

type HandlerEx added in v0.1.100

type HandlerEx interface {
	Handler(id uint64, prefix string, path string, w http.ResponseWriter, r *http.Request) (processed bool, basePath string)
}

HandlerEx --

type StatusFunc added in v0.1.47

type StatusFunc func(id uint64, prefix string, path string, w http.ResponseWriter, r *http.Request)

StatusFunc --

Jump to

Keyboard shortcuts

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