yakhttp

package
v1.2.9-sp7 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientPool sync.Map
View Source
var HttpExports = map[string]interface{}{

	"Raw": rawRequest,

	"Get": func(url string, opts ...HttpOption) (*YakHttpResponse, error) {
		return httpRequest("GET", url, opts...)
	},
	"Post": func(url string, opts ...HttpOption) (*YakHttpResponse, error) {
		return httpRequest("POST", url, opts...)
	},
	"Request": httpRequest,

	"Do":         Do,
	"NewRequest": NewHttpNewRequest,

	"GetAllBody": GetAllBody,

	"dump":     dump,
	"show":     httpShow,
	"dumphead": dumphead,
	"showhead": func(i interface{}) {
		rsp, err := dumphead(i)
		if err != nil {
			log.Errorf("show failed: %s", err)
			return
		}
		fmt.Println(string(rsp))
	},

	"ua":        UserAgent,
	"useragent": UserAgent,
	"fakeua":    FakeUserAgent,

	"header": Header,

	"cookie": Cookie,

	"body": Body,

	"json": JsonBody,

	"params":     GetParams,
	"postparams": PostParams,

	"proxy": YakHttpConfig_Proxy,

	"timeout": yakHttpConfig_Timeout,

	"redirect":   RedirectHandler,
	"noredirect": NoRedirect,

	"session": Session,

	"uarand": _getuarand,
}
View Source
var NewHttpNewRequest = func(method, url string, opts ...HttpOption) (*YakHttpRequest, error) {
	req, err := http.NewRequest(method, url, nil)
	if err != nil {
		return nil, err
	}

	rawReq := &YakHttpRequest{
		Request: req,
	}
	for _, op := range opts {
		op(rawReq)
	}
	return rawReq, nil
}

Functions

func Do

func Do(req *YakHttpRequest) (*http.Response, error)

func GetAllBody

func GetAllBody(raw interface{}) []byte

func GetClient

func GetClient(session interface{}) *http.Client

Types

type HttpOption

type HttpOption func(req *YakHttpRequest)

func Body

func Body(value interface{}) HttpOption
func Cookie(value interface{}) HttpOption

func FakeUserAgent

func FakeUserAgent() HttpOption

func GetParams

func GetParams(i interface{}) HttpOption

GetParams set query params

func Header(key, value interface{}) HttpOption

func JsonBody

func JsonBody(value interface{}) HttpOption

func NoRedirect

func NoRedirect() HttpOption

func PostParams

func PostParams(i interface{}) HttpOption

PostParams set post params

func RedirectHandler

func RedirectHandler(c func(r *http.Request, vias []*http.Request) bool) HttpOption

func Session

func Session(value interface{}) HttpOption

func UserAgent

func UserAgent(value interface{}) HttpOption

func YakHttpConfig_Proxy added in v1.2.6

func YakHttpConfig_Proxy(values ...string) HttpOption

type YakHttpRequest

type YakHttpRequest struct {
	*http.Request
	// contains filtered or unexported fields
}

type YakHttpResponse

type YakHttpResponse struct {
	*http.Response
}

func (*YakHttpResponse) Data

func (y *YakHttpResponse) Data() string

func (*YakHttpResponse) GetHeader

func (y *YakHttpResponse) GetHeader(key string) string

func (*YakHttpResponse) Json

func (y *YakHttpResponse) Json() interface{}

func (*YakHttpResponse) Raw

func (y *YakHttpResponse) Raw() []byte

Jump to

Keyboard shortcuts

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