MCPcopy Create free account
hub / github.com/imroc/req / C

Function C

client.go:1587–1622  ·  view source on GitHub ↗

C create a new client.

()

Source from the content-addressed store, hash-verified

1585
1586// C create a new client.
1587func C() *Client {
1588 t := T()
1589
1590 httpClient := &http.Client{
1591 Transport: t,
1592 Timeout: 2 * time.Minute,
1593 }
1594 beforeRequest := []RequestMiddleware{
1595 parseRequestHeader,
1596 parseRequestCookie,
1597 parseRequestURL,
1598 parseRequestBody,
1599 }
1600 afterResponse := []ResponseMiddleware{
1601 parseResponseBody,
1602 handleDownload,
1603 }
1604 c := &Client{
1605 AllowGetMethodPayload: true,
1606 beforeRequest: beforeRequest,
1607 afterResponse: afterResponse,
1608 log: createDefaultLogger(),
1609 httpClient: httpClient,
1610 Transport: t,
1611 jsonMarshal: json.Marshal,
1612 jsonUnmarshal: json.Unmarshal,
1613 xmlMarshal: xml.Marshal,
1614 xmlUnmarshal: xml.Unmarshal,
1615 cookiejarFactory: memoryCookieJarFactory,
1616 }
1617 c.SetRedirectPolicy(DefaultRedirectPolicy())
1618 c.initCookieJar()
1619
1620 c.initTransport()
1621 return c
1622}
1623
1624// SetCookieJarFactory set the functional factory of cookie jar, which creates
1625// cookie jar that store cookies for underlying `http.Client`. After client clone,

Callers 4

tcFunction · 0.85
TestCloneCookieJarFunction · 0.85
client.goFile · 0.85
NewClientFunction · 0.85

Calls 6

SetRedirectPolicyMethod · 0.95
initCookieJarMethod · 0.95
initTransportMethod · 0.95
TFunction · 0.85
createDefaultLoggerFunction · 0.85
DefaultRedirectPolicyFunction · 0.85

Tested by 2

tcFunction · 0.68
TestCloneCookieJarFunction · 0.68