httpx

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: Apache-2.0, BSD-3-Clause, MIT, + 2 more Imports: 23 Imported by: 0

Documentation

Overview

Package httpx 编码相关

Package httpx http相关

Package httpx http请求主体

Package httpx http option

Package httpx http response

Package httpx title

Package httpx provides HTTP utility functions and types for handling user agents

Index

Constants

View Source
const (
	// HTTP defines the plain http scheme
	HTTP = "http"
	// HTTPS defines the secure http scheme
	HTTPS = "https"
	// HTTPorHTTPS defines the both http and https scheme
	HTTPorHTTPS = "http|https"
)

Variables

This section is empty.

Functions

func Decodebig5

func Decodebig5(s []byte) ([]byte, error)

Decodebig5 converts BIG5 to UTF-8

func Decodegbk

func Decodegbk(s []byte) ([]byte, error)

Decodegbk converts GBK to UTF-8

func DumpRequest

func DumpRequest(req *retryablehttp.Request) (string, error)

DumpRequest to string

func DumpRequestRaw

func DumpRequestRaw(req *retryablehttp.Request) string

DumpRequestRaw 导出请求包原文

func DumpResponse

func DumpResponse(resp *http.Response) (string, error)

DumpResponse to string

func Encodebig5

func Encodebig5(s []byte) ([]byte, error)

Encodebig5 converts UTF-8 to BIG5

func ExtractTitle

func ExtractTitle(resp string) (title string)

ExtractTitle from a response

func GetRandomUserAgent

func GetRandomUserAgent() string

GetRandomUserAgent returns a random user agent string from the predefined list. It uses math/rand to generate a random index.

func ParseRequest

func ParseRequest(req string, unsafe bool) (method, path string, headers map[string]string, body string, err error)

ParseRequest from raw string

Types

type HTTPOptions

type HTTPOptions struct {
	Timeout          time.Duration
	RetryMax         int
	FollowRedirects  bool
	HTTPProxy        string
	Unsafe           bool
	DefaultUserAgent string
	Dialer           *fastdialer.Dialer
	CustomHeaders    []string
}

HTTPOptions http options

type HTTPX

type HTTPX struct {
	CustomHeaders map[string]string
	Options       *HTTPOptions
	// contains filtered or unexported fields
}

HTTPX represent an instance of the library client

func NewHttpx

func NewHttpx(options *HTTPOptions) (*HTTPX, error)

NewHttpx instance

func (*HTTPX) Get

func (h *HTTPX) Get(targetUrl string, headers map[string]string) (*Response, error)

Get on get request

func (*HTTPX) POST

func (h *HTTPX) POST(targetUrl string, data interface{}, headers map[string]string) (*Response, error)

POST on post request

type Response

type Response struct {
	*http.Response
	StatusCode    int
	Headers       map[string][]string
	Data          []byte
	DataStr       string
	ContentLength int
	Title         string
}

Response contains the response to a server

func (*Response) DumpResponse

func (r *Response) DumpResponse() string

DumpResponse 导出返回包

func (*Response) GetHeader

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

GetHeader value

func (*Response) GetHeaderPart

func (r *Response) GetHeaderPart(name, sep string) string

GetHeaderPart with offset

func (*Response) GetHeaderRaw

func (r *Response) GetHeaderRaw() string

GetHeaderRaw 获得header文本

type UserAgent

type UserAgent []string

UserAgent represents a slice of user agent strings

Jump to

Keyboard shortcuts

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