httpclient

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package network client negotiator @author Arditya Kekasi

Package httpclient @author Daud Valentino

Index

Constants

View Source
const (
	Accept                        = "Accept"
	AcceptCharset                 = "Accept-Charset"
	AcceptEncoding                = "Accept-Encoding"
	AcceptLanguage                = "Accept-Language"
	Authorization                 = "Authorization"
	CacheControl                  = "Cache-Control"
	ContentLength                 = "Content-Length"
	ContentMD5                    = "Content-MD5"
	ContentType                   = "Content-Type"
	DoNotTrack                    = "DNT"
	IfMatch                       = "If-Match"
	IfModifiedSince               = "If-Modified-Since"
	IfNoneMatch                   = "If-None-Match"
	IfRange                       = "If-Range"
	IfUnmodifiedSince             = "If-Unmodified-Since"
	MaxForwards                   = "Max-Forwards"
	ProxyAuthorization            = "Proxy-Authorization"
	Pragma                        = "Pragma"
	Range                         = "Range"
	Referer                       = "Referer"
	UserAgent                     = "User-Agent"
	TE                            = "TE"
	Via                           = "Via"
	Warning                       = "Warning"
	Cookie                        = "Cookie"
	Origin                        = "Origin"
	AcceptDatetime                = "Accept-Datetime"
	XRequestedWith                = "X-Requested-With"
	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	AccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	AccessControlMaxAge           = "Access-Control-Max-Age"
	AccessControlRequestMethod    = "Access-Control-Request-Method"
	AccessControlRequestHeaders   = "Access-Control-Request-Headers"
	AcceptPatch                   = "Accept-Patch"
	AcceptRanges                  = "Accept-Ranges"
	Allow                         = "Allow"
	ContentEncoding               = "Content-Encoding"
	ContentLanguage               = "Content-Language"
	ContentLocation               = "Content-Location"
	ContentDisposition            = "Content-Disposition"
	ContentRange                  = "Content-Range"
	ETag                          = "ETag"
	Expires                       = "Expires"
	LastModified                  = "Last-Modified"
	Link                          = "Link"
	Location                      = "Location"
	P3P                           = "P3P"
	ProxyAuthenticate             = "Proxy-Authenticate"
	Refresh                       = "Refresh"
	RetryAfter                    = "Retry-After"
	Server                        = "Server"
	SetCookie                     = "Set-Cookie"
	StrictTransportSecurity       = "Strict-Transport-Security"
	TransferEncoding              = "Transfer-Encoding"
	Upgrade                       = "Upgrade"
	Vary                          = "Vary"
	WWWAuthenticate               = "WWW-Authenticate"
	Connection                    = "Connection"
	MediaTypeJSON                 = "application/json"
	ClinetID                      = "Client-ID"
	TransactionID                 = "Transaction-ID"
)

HTTP headers

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)

NewRequest returns a new Request given a context, method, URL, and optional body.

If the provided body is also an io.Closer, the returned Request.Body is set to body and will be closed by the Client methods Do, Post, and PostForm, and Transport.RoundTrip.

NewRequest returns a Request suitable for use with Client.Do or Transport.RoundTrip. To create a request for use with testing a Server Handler, either use the NewRequest function in the net/http/httptest package, use ReadRequest, or manually update the Request fields. See the Request type's documentation for the difference between inbound and outbound request fields.

If body is of type *bytes.Buffer, *bytes.Reader, or *strings.Reader, the returned request's ContentLength is set to its exact value (instead of -1), GetBody is populated (so 307 and 308 redirects can replay the body), and Body is set to NoBody if the ContentLength is 0.

func Normalize

func Normalize(header string) string

Normalize formats the input header to the formation of "Xxx-Xxx".

Types

type Headers

type Headers map[string]string

Headers content headers parameter

func (Headers) Add

func (h Headers) Add(key, value string) Headers

Add adds the key, value pair to the header.

func (Headers) Get

func (h Headers) Get(key string) string

Get Header Value

type RequestOptions

type RequestOptions struct {
	Payload       interface{}
	Request       interface{}
	URL           string
	Header        Headers
	Method        string
	TimeoutSecond int
	Context       context.Context
}

RequestOptions provide option parameter client request

type Response

type Response struct {
	StatusCode int
	Body       []byte
	BodyStr    string
	Latency    time.Duration
	Header     http.Header
}

ClientResponse representation of http client response

func Request

func Request(option RequestOptions) (Response, error)

ClientRequest http client request with option

func (Response) DecodeJSON

func (cr Response) DecodeJSON(dest interface{}) error

DecodeJSON decode response byte to struct

func (Response) GetHeader

func (cr Response) GetHeader() http.Header

Header return http header response

func (Response) GetLatency

func (cr Response) GetLatency() time.Duration

Header return http status response

func (Response) RawByte

func (cr Response) RawByte() []byte

RawByte return raw byte data

func (Response) Status

func (cr Response) Status() int

Header return http status response

func (Response) String

func (cr Response) String() string

String cast response byte to string

Jump to

Keyboard shortcuts

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