httpx

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// EmptyCompressorAlgorithm just using to beautify codes.
	EmptyCompressorAlgorithm = ""
)

Variables

View Source
var BodyTypeMap = map[string]string{"none": "", "text": "text/plain", "json": "application/json", "html": "text/html", "xml": "application/xml", "javascript": "application/javascript", "form": ""}

Functions

func DownloadFile

func DownloadFile(filepath string, uri string) error

func IsHttpUrl

func IsHttpUrl(str string) error

func IsValidUrl

func IsValidUrl(uri string) bool

func ReadFile

func ReadFile(uri string) (io.ReadCloser, error)

ReadFile Need to close the return reader

func Send

func Send(logger api.Logger, client *http.Client, u string, method string, opts ...HTTPRequestOptions) (*http.Response, error)

Send v must be a []byte or map

Types

type HTTPRequestOptions

type HTTPRequestOptions func(req *http.Request) error

HTTPRequestOptions using for customized http request.

func WithBody

func WithBody(body any, bodyType string, retErrOnConvertFailed bool, compressor message.Compressor, compressAlgorithm string) HTTPRequestOptions

WithBody specifies the request body.

NOTICE: If the body type is form, this function will try to convert body as map[string]any, and if retErrOnConvertFailed is true, it returns an error on convert failure, it converts data to a raw string if set to false.

If compressor is not nil and compressAlgorithm is not empty will compress body with given message.Compressor and set request header with key 'Accept-Encoding' and value to given compressAlgorithm.

func WithHeadersMap

func WithHeadersMap(headers map[string]string) HTTPRequestOptions

WithHeadersMap adds the all header k-v pairs into request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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