http

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Second * 30

Variables

View Source
var DefaultHttpHeaders = map[string]string{
	Header.Accept:         "application/json",
	Header.AcceptEncoding: "gzip, deflate",
	Header.ContentType:    "application/json; charset=UTF-8",
}
View Source
var Header = &headerList{
	Accept:          "Accept",
	AcceptEncoding:  "Accept-Encoding",
	AcceptLanguage:  "Accept-Language",
	Authorization:   "Authorization",
	ContentEncoding: "Content-Encoding",
	ContentType:     "Content-Type",
	UserAgent:       "User-Agent",
}

Functions

func ContainsKnownScheme added in v0.0.6

func ContainsKnownScheme(s string) bool

func ExtractBody

func ExtractBody(response *http.Response) ([]byte, error)

func ExtractCookies added in v0.0.5

func ExtractCookies(response *http.Response) []http.Cookie

func IsKnownMethod added in v0.0.11

func IsKnownMethod(s string) bool

func NewDefaultResponse added in v0.0.12

func NewDefaultResponse(code int, h http.Header, c []http.Cookie, b []byte) *defaultResponse

func ProduceDefaultClient

func ProduceDefaultClient() *http.Client

func StatusBelongs added in v0.0.14

func StatusBelongs(status Status, code int) bool

Types

type Request

type Request interface {
	GetHeaders() map[string]string
	GetMethod() string
	GetEndpoint() string
	GetCookies() []http.Cookie
	GetValues() string
	GetPayload() []byte
}

type Requester

type Requester interface {
	Do(Request, []int) (Response, error)

	DebugLog(...string)

	GetEndpoint(Request) (*url.URL, error)
}

func NewDefaultRequester

func NewDefaultRequester(ctx context.Context, host string, debug bool) Requester

func NewDefaultRequesterWithTimeout added in v0.0.16

func NewDefaultRequesterWithTimeout(ctx context.Context, host string, timeout time.Duration, debug bool) Requester

type Response added in v0.0.5

type Response interface {
	StatusCode() int
	Headers() http.Header
	Cookies() []http.Cookie
	Body() []byte
}

type Status added in v0.0.14

type Status int
const (
	Information Status = iota
	Successful
	Redirection
	ClientError
	ServerError
)

Jump to

Keyboard shortcuts

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