mhttp

package
v0.4.74 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &http.Client{
	Transport: &http.Transport{
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		MaxIdleConns:          500,
		MaxIdleConnsPerHost:   500,
		IdleConnTimeout:       30 * time.Second,
		TLSClientConfig:       &tls.Config{InsecureSkipVerify: true},
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
	},
	Timeout: 10 * time.Second,
}
View Source
var DefaultHttpHandlerInstance = DefaultHttpHandler{}
View Source
var HeaderNames = &headerName{
	Accept:                        "accept",
	AcceptCharset:                 "accept-charset",
	AcceptEncoding:                "accept-encoding",
	AcceptLanguage:                "accept-language",
	AcceptRanges:                  "accept-ranges",
	AcceptPatch:                   "accept-patch",
	AcceptControlAllowCredentials: "access-control-allow-credentials",
	AcceptControlAllowHeaders:     "access-control-allow-headers",
	AcceptControlAllowMethods:     "access-control-allow-methods",
	AcceptControlAllowOrigin:      "access-control-allow-origin",
	AcceptControlExposeHeaders:    "access-control-expose-headers",
	AcceptControlMaxAge:           "access-control-max-age",
	AcceptControlRequestHeaders:   "access-control-request-headers",
	AcceptControlRequestMethod:    "access-control-request-method",
	Age:                           "age",
	Allow:                         "allow",
	Authorization:                 "authorization",
	CacheControl:                  "cache-control",
	Connection:                    "connection",
	ContentEncoding:               "content-encoding",
	ContentLanguage:               "content-language",
	ContentLength:                 "content-length",
	ContentLocation:               "content-location",
	ContentTransferEncoding:       "content-transfer-encoding",
	ContentDisposition:            "content-disposition",
	ContentMd5:                    "content-md5",
	ContentRange:                  "content-range",
	ContentSecurityPolicy:         "content-security-policy",
	ContentType:                   "content-type",
	Cookie:                        "cookie",
	Date:                          "date",
	Dnt:                           "dnt",
	Etag:                          "etag",
	Expect:                        "expect",
	Expires:                       "expires",
	From:                          "from",
	Host:                          "host",
	IfMatch:                       "if-match",
	IfNoneMatch:                   "if-none-match",
	IfRange:                       "if-range",
	IfUnmodifiedSince:             "if-unmodified-since",
	KeepAlive:                     "keep-alive",
	LastModified:                  "last-modified",
	Location:                      "location",
	MaxForwards:                   "max-forwards",
	Origin:                        "origin",
	Pragma:                        "pragma",
	ProxyAuthenticate:             "proxy-authenticate",
	ProxyAuthorization:            "proxy-authorization",
	ProxyConnection:               "proxy-connection",
	Range:                         "range",
	Referer:                       "referer",
	RetryAfter:                    "retry-after",
	SecWebsocketKey1:              "sec-websocket-key1",
	SecWebsocketKey2:              "sec-websocket-key2",
	SecWebsocketLocation:          "sec-websocket-location",
	SecWebsocketOrigin:            "sec-websocket-origin",
	SecWebsocketProtocol:          "sec-websocket-protocol",
	SecWebsocketVersion:           "sec-websocket-version",
	SecWebsocketKey:               "sec-websocket-key",
	SecWebsocketAccept:            "sec-websocket-accept",
	SecWebsocketExtensions:        "sec-websocket-extensions",
	Server:                        "server",
	SetCookie:                     "set-cookie",
	SetCookie2:                    "set-cookie2",
	Te:                            "te",
	Trailer:                       "trailer",
	TrailerEncoding:               "transfer-encoding",
	Upgrade:                       "upgrade",
	UpgradeInsecureRequests:       "upgrade-insecure-requests",
	UserAgent:                     "user-agent",
	Vary:                          "vary",
	Via:                           "via",
	Warning:                       "warning",
	WebsocketLocation:             "websocket-location",
	WebsocketOrigin:               "websocket-origin",
	WebsocketProtocol:             "websocket-protocol",
	WwwAuthenticate:               "www-authenticate",
	XFrameOptions:                 "x-frame-options",
	XRequestedWith:                "x-requested-with",
}

Functions

func URL

func URL(rawURL string, params map[string]string) (string, error)

Types

type DefaultHttpHandler added in v0.4.70

type DefaultHttpHandler struct {
}

func (DefaultHttpHandler) Run added in v0.4.70

func (me DefaultHttpHandler) Run(ce Request, body io.Reader) (*Response, error)

type HttpHandler added in v0.4.70

type HttpHandler interface {
	Run(request Request, body io.Reader) (*Response, error)
}

type Request

type Request struct {
	Url     string
	Method  string
	Params  map[string]string
	Head    http.Header
	Body    io.Reader
	Charset string
	Handler HttpHandler
}

func NewRequest

func NewRequest(method, url string) *Request

func NewRequest2

func NewRequest2(method, url, headerName, headerValue string) *Request

func NewRequest3

func NewRequest3(method, url string, header map[string]string) *Request

func (*Request) AddHeader added in v0.4.70

func (ce *Request) AddHeader(headerName, headerValue string) *Request

func (*Request) AddHeaderMap added in v0.4.70

func (ce *Request) AddHeaderMap(header map[string]string) *Request

func (*Request) File

func (ce *Request) File(fieldName, filename string, reader io.Reader) (*Response, error)

func (*Request) File2

func (ce *Request) File2(fieldName, filename string, reader io.Reader, attr map[string]string) (*Response, error)

func (*Request) FormBody added in v0.4.70

func (ce *Request) FormBody(data string) (*Response, error)

func (*Request) FormBody2 added in v0.4.70

func (ce *Request) FormBody2(data map[string]string) (*Response, error)

func (*Request) FormBody3 added in v0.4.70

func (ce *Request) FormBody3(reader io.Reader) (*Response, error)

func (*Request) Get

func (ce *Request) Get() (*Response, error)

func (*Request) GetParams added in v0.4.73

func (ce *Request) GetParams(params map[string]string) (*Response, error)

func (*Request) JsonBody added in v0.4.70

func (ce *Request) JsonBody(data string) (*Response, error)

func (*Request) JsonBody2 added in v0.4.70

func (ce *Request) JsonBody2(data any) (*Response, error)

func (*Request) JsonBody3 added in v0.4.70

func (ce *Request) JsonBody3(reader io.Reader) (*Response, error)

type Response

type Response struct {
	Url           string
	Method        string
	Status        string
	StatusCode    int
	OK            bool
	ContentLength int64
	Data          *bytes.Buffer
	Header        http.Header
	Metadata      *http.Response
	// contains filtered or unexported fields
}
func Head(url string) (*Response, error)

func (*Response) Buffer

func (ce *Response) Buffer() (*bytes.Buffer, error)

func (*Response) Charset

func (ce *Response) Charset() string

func (*Response) ContentType

func (ce *Response) ContentType() string

func (*Response) Cookie

func (ce *Response) Cookie() []*http.Cookie

func (*Response) GetHeader

func (ce *Response) GetHeader(name string) string

func (*Response) Json

func (ce *Response) Json(dest any) error

func (*Response) Str

func (ce *Response) Str() (string, error)

Jump to

Keyboard shortcuts

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