C create a new client.
()
| 1585 | |
| 1586 | // C create a new client. |
| 1587 | func 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, |