httplib

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultSetting

func SetDefaultSetting(setting HttpSettings)

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.

Types

type HttpRequest

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

func Delete

func Delete(url string) *HttpRequest

Delete请求

func Get

func Get(url string) *HttpRequest

Get请求

func Head(url string) *HttpRequest

Head returns *HttpRequest with HEAD method.

func NewRequest added in v1.0.9

func NewRequest(url, method string) *HttpRequest

func Patch added in v1.0.9

func Patch(url string) *HttpRequest

Patch请求

func Post

func Post(url string) *HttpRequest

Post请求

func Put

func Put(url string) *HttpRequest

Put请求

func (*HttpRequest) Body

func (this *HttpRequest) Body(data interface{}) *HttpRequest

Body adds request raw body. it supports string and []byte.

func (*HttpRequest) Bytes

func (this *HttpRequest) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*HttpRequest) Debug

func (this *HttpRequest) Debug(isdebug bool) *HttpRequest

Debug sets show debug or not when executing request.

func (*HttpRequest) Header

func (this *HttpRequest) Header(key, value string) *HttpRequest

Header add header item string in request.

func (*HttpRequest) Param

func (this *HttpRequest) Param(key, value string) *HttpRequest

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*HttpRequest) PostFile

func (this *HttpRequest) PostFile(formname, filename string) *HttpRequest

func (*HttpRequest) Response

func (this *HttpRequest) Response() (*http.Response, error)

Response executes request client gets response mannually.

func (*HttpRequest) SetBasicAuth

func (this *HttpRequest) SetBasicAuth(username, password string) *HttpRequest

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*HttpRequest) SetCookie

func (this *HttpRequest) SetCookie(cookie *http.Cookie) *HttpRequest

SetCookie add cookie into request.

func (*HttpRequest) SetProtocolVersion

func (this *HttpRequest) SetProtocolVersion(vers string) *HttpRequest

Set the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*HttpRequest) SetProxy

func (this *HttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpRequest

Set http proxy example:

func(req *http.Request) (*url.URL, error) {
	u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
	return u, nil
}

func (*HttpRequest) SetTLSClientConfig

func (this *HttpRequest) SetTLSClientConfig(config *tls.Config) *HttpRequest

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*HttpRequest) SetTimeout

func (this *HttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpRequest

SetTimeout sets connect time out and read-write time out for Request.

func (*HttpRequest) SetTransport

func (this *HttpRequest) SetTransport(transport http.RoundTripper) *HttpRequest

Set transport to

func (*HttpRequest) SetUserAgent

func (this *HttpRequest) SetUserAgent(useragent string) *HttpRequest

SetUserAgent sets User-Agent header field

func (*HttpRequest) Setting

func (this *HttpRequest) Setting(setting HttpSettings) *HttpRequest

重置http设置

func (*HttpRequest) String

func (this *HttpRequest) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*HttpRequest) ToFile

func (this *HttpRequest) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*HttpRequest) ToJson

func (this *HttpRequest) ToJson(v interface{}) error

ToJson returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*HttpRequest) ToXml

func (this *HttpRequest) ToXml(v interface{}) error

ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.

func (*HttpRequest) UseCookieJar

func (this *HttpRequest) UseCookieJar(jar http.CookieJar) *HttpRequest

SetEnableCookie sets cookiejar

type HttpSettings

type HttpSettings struct {
	ShowDebug        bool
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	TlsClientConfig  *tls.Config
	Proxy            func(*http.Request) (*url.URL, error)
	Transport        http.RoundTripper
}

HttpSettings

type Jar

type Jar struct {

	//
	sync.Mutex
	// contains filtered or unexported fields
}

Jar implements the http.CookieJar interface from the net/http package.

func NewJar

func NewJar(filename string, o *Options) (*Jar, error)

New returns a new cookie jar. A nil *Options is equivalent to a zero Options.

func (*Jar) Cookies

func (j *Jar) Cookies(u *url.URL) (cookies []*http.Cookie)

Cookies implements the Cookies method of the http.CookieJar interface.

It returns an empty slice if the URL's scheme is not HTTP or HTTPS.

func (*Jar) SetCookies

func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies implements the SetCookies method of the http.CookieJar interface.

It does nothing if the URL's scheme is not HTTP or HTTPS.

type Options

type Options struct {
	// PublicSuffixList is the public suffix list that determines whether
	// an HTTP server can set a cookie for a domain.
	//
	// A nil value is valid and may be useful for testing but it is not
	// secure: it means that the HTTP server for foo.co.uk can set a cookie
	// for bar.co.uk.
	PublicSuffixList PublicSuffixList
}

Options are the options for creating a new Jar.

type PublicSuffixList

type PublicSuffixList interface {
	// PublicSuffix returns the public suffix of domain.
	//
	// TODO: specify which of the caller and callee is responsible for IP
	// addresses, for leading and trailing dots, for case sensitivity, and
	// for IDN/Punycode.
	PublicSuffix(domain string) string

	// String returns a description of the source of this public suffix
	// list. The description will typically contain something like a time
	// stamp or version number.
	String() string
}

PublicSuffixList provides the public suffix of a domain. For example:

  • the public suffix of "example.com" is "com",
  • the public suffix of "foo1.foo2.foo3.co.uk" is "co.uk", and
  • the public suffix of "bar.pvt.k12.ma.us" is "pvt.k12.ma.us".

Implementations of PublicSuffixList must be safe for concurrent use by multiple goroutines.

An implementation that always returns "" is valid and may be useful for testing but it is not secure: it means that the HTTP server for foo.com can set a cookie for bar.com.

A public suffix list implementation is in the package golang.org/x/net/publicsuffix.

Jump to

Keyboard shortcuts

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