httplib

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Zlib Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client http request client provides more useful methods for requesting one url than http.Request.

func New

func New() *Client

New returns http Client with default settings.

func NewClient

func NewClient(config *Config) *Client

NewClient returns http Client with custom settings.

func NewClientWithProxy

func NewClientWithProxy(proxy func(*http.Request) (*url.URL, error)) *Client

NewClientWithProxy returns http Client with custom proxy property. example:

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

func NewTimeoutClient

func NewTimeoutClient(second int64) *Client

NewTimeoutClient returns http Client with custom timeout.

func (*Client) DELETE

func (c *Client) DELETE(url string) (*http.Response, error)

DELETE sends request with DELETE method.

func (*Client) Do

func (c *Client) Do(method, url string, data []byte) (*http.Response, error)

Do sends request with specified method.

func (*Client) GET

func (c *Client) GET(url string) (*http.Response, error)

GET sends request with GET method.

func (*Client) PATCH

func (c *Client) PATCH(url string) (*http.Response, error)

PATCH sends request with PATCH method.

func (*Client) POST

func (c *Client) POST(url string) (*http.Response, error)

POST sends request with POST method.

func (*Client) PUT

func (c *Client) PUT(url string) (*http.Response, error)

PUT sends request with PUT method.

func (*Client) PostFile

func (c *Client) PostFile(url, fileName, field string, fileContent []byte) (*http.Response, error)

PostFile sends POST request with file content.

func (*Client) PostRaw

func (c *Client) PostRaw(url string, data []byte) (*http.Response, error)

PostRaw sends POST request with raw content.

func (*Client) SetContentType

func (c *Client) SetContentType(contentType ContentType) *Client

SetContentType sets "Content-Type" header field.

func (*Client) SetCookie

func (c *Client) SetCookie(cookie *http.Cookie) *Client

SetCookie add cookie into request.

func (*Client) SetHeader

func (c *Client) SetHeader(h map[string]string) *Client

SetHeader sets http header. Keep the first letter of param is capitalized.

func (*Client) SetHeaderFace

func (c *Client) SetHeaderFace(h map[string]string) *Client

SetHeaderFace sets http header. Keep param is original words, don't change the case of letters. https://golang.org/pkg/net/http/#CanonicalHeaderKey

func (*Client) SetHost

func (c *Client) SetHost(host string) *Client

SetHost sets host.

func (*Client) SetParams

func (c *Client) SetParams(p map[string][]string) *Client

SetParams adds http query param in to request.

type Config

type Config struct {
	Timeout            time.Duration     // Time out
	DisableKeepAlives  bool              // Disable keep alives
	InsecureSkipVerify bool              // Skip secure verify
	Encode             bool              // Encode URL for GET method
	IsEncodeForGo      bool              // To encode URL by golang lib
	Charset            string            // Charset (default UTF-8)
	Certificates       []tls.Certificate // SSL certificate
	Proxy              func(*http.Request) (*url.URL, error)
}

Config is used to override the default http client settings.

func NewHttpConfig

func NewHttpConfig() *Config

NewHttpConfig returns default http config.

type ContentType

type ContentType string

ContentType is used to indicate the media type of the resource.

const (
	Raw  ContentType = "application/raw"  // Raw MIME type
	XML  ContentType = "application/xml"  // XML MIME type
	JSON ContentType = "application/json" // JSON MIME type
	TEXT ContentType = "application/text" // Text MIME type
	HTML ContentType = "application/html" // HTML MIME type
)

Jump to

Keyboard shortcuts

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