本文整理汇总了Golang中net/http.Client.Jar方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Jar方法的具体用法?Golang Client.Jar怎么用?Golang Client.Jar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Client
的用法示例。
在下文中一共展示了Client.Jar方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewSession
// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
func NewSession(client *http.Client, authConfig *cliconfig.AuthConfig, endpoint *Endpoint) (r *Session, err error) {
r = &Session{
authConfig: authConfig,
client: client,
indexEndpoint: endpoint,
}
var alwaysSetBasicAuth bool
// If we're working with a standalone private registry over HTTPS, send Basic Auth headers
// alongside all our requests.
if endpoint.VersionString(1) != IndexServerAddress() && endpoint.URL.Scheme == "https" {
info, err := endpoint.Ping()
if err != nil {
return nil, err
}
if info.Standalone && authConfig != nil {
logrus.Debugf("Endpoint %s is eligible for private registry. Enabling decorator.", endpoint.String())
alwaysSetBasicAuth = true
}
}
// Annotate the transport unconditionally so that v2 can
// properly fallback on v1 when an image is not found.
client.Transport = AuthTransport(client.Transport, authConfig, alwaysSetBasicAuth)
jar, err := cookiejar.New(nil)
if err != nil {
return nil, errors.New("cookiejar.New is not supposed to return an error")
}
client.Jar = jar
return r, nil
}
示例2: NewArgs
func NewArgs(c *http.Client) *Args {
if c.Jar == nil {
options := cookiejar.Options{
PublicSuffixList: publicsuffix.List,
}
jar, _ := cookiejar.New(&options)
c.Jar = jar
}
headers := map[string]string{}
for k, v := range DefaultHeaders {
headers[k] = v
}
return &Args{
Client: c,
Headers: headers,
Cookies: nil,
Data: nil,
Params: nil,
Files: nil,
Json: nil,
Proxy: "",
BasicAuth: BasicAuth{},
}
}
示例3: hakai
func hakai(c http.Client, config *Config, offset map[string]int) {
u, err := url.Parse(config.Domain)
if err != nil {
log.Fatal(err)
}
queryParams := map[string]string{}
for k, v := range config.QueryParams {
vv := ReplaceNames(v, offset)
queryParams[k] = vv
}
cookieJar, _ := cookiejar.New(nil)
c.Jar = cookieJar
attacker := Attacker{
Client: &c,
Url: u,
Gzip: config.Gzip,
UserAgent: config.UserAgent,
QueryParams: &queryParams,
ExVarOffset: offset,
}
for offset, action := range config.Actions {
attacker.Action = action
attacker.Attack(offset)
}
}
示例4: NewEngine
func NewEngine(client *http.Client, apple_id, password string) (engine *ICloudEngine, e error) {
cookieJar, err := cookiejar.New(nil)
if err != nil {
log.Fatal(err)
}
client.Jar = cookieJar
var version *ICloudVersion
if version, e = getICloudVersion(client); e != nil {
return nil, e
}
engine = new(ICloudEngine)
engine.ReportedVersion = version
info := map[string]string{
"apple_id": apple_id,
"password": password,
"extended_login": "false",
}
data, _ := json.Marshal(info)
var req *http.Request
if req, e = http.NewRequest("POST", loginURL, bytes.NewReader(data)); e != nil {
return nil, e
}
v := url.Values{}
v.Add("clientBuildNumber", version.BuildNumber)
v.Add("clientID", ClientID)
req.URL.RawQuery = v.Encode()
req.Header.Set("Content-Type", "text/plain")
req.Header.Add("Origin", "https://www.icloud.com")
req.Header.Add("Referer", "https://www.icloud.com/")
req.Header.Set("User-Agent", "Opera/9.52 (X11; Linux i686; U; en)")
var resp *http.Response
if resp, e = client.Do(req); e != nil {
return nil, e
}
defer resp.Body.Close()
if resp.StatusCode == 421 {
return nil, ErrFailedLogin
}
var body []byte
if body, e = ioutil.ReadAll(resp.Body); e != nil {
return nil, e
}
json.Unmarshal(body, engine)
engine.Client = client
engine.ClientID = ClientID
return engine, nil
}
示例5: getCsrfToken
func getCsrfToken(client *http.Client, url string) string {
// CSRF support
jar := &cookieJar{}
jar.jar = make(map[string][]*http.Cookie)
client.Jar = jar
headResponse, err := client.Head(url)
checkError(err)
token := headResponse.Header.Get(csrfTokenHeader)
return token
}
示例6: do
func (self *Client) do(req *http.Request) (*http.Response, error) {
var client http.Client
if self.TlsTransport != nil {
client = http.Client{
Transport: self.TlsTransport,
}
} else {
client = http.Client{}
}
// Adding cookie jar
if self.CookieJar != nil {
client.Jar = self.CookieJar
}
// Copying headers
for k := range self.Header {
req.Header.Set(k, self.Header.Get(k))
}
if req.Body == nil {
req.Header.Del("Content-Type")
req.Header.Del("Content-Length")
}
res, err := client.Do(req)
if debugLevelEnabled(debugLevelVerbose) {
log.Printf("Fetching %v\n", req.URL.String())
log.Printf("> %s %s", req.Method, req.Proto)
for k := range req.Header {
for kk := range req.Header[k] {
log.Printf("> %s: %s", k, req.Header[k][kk])
}
}
log.Printf("< %s %s", res.Proto, res.Status)
for k := range res.Header {
for kk := range res.Header[k] {
log.Printf("< %s: %s", k, res.Header[k][kk])
}
}
log.Printf("\n")
}
return res, err
}
示例7: newHttpTransporter
func newHttpTransporter() (trans *httpTransporter) {
tr := new(http.Transport)
tr.DisableCompression = true
tr.DisableKeepAlives = false
tr.MaxIdleConnsPerHost = 4
jar := cookieJar
if DisableGlobalCookie {
jar, _ = cookiejar.New(nil)
}
client := new(http.Client)
client.Jar = jar
client.Transport = tr
trans = new(httpTransporter)
trans.Client = client
trans.Header = new(http.Header)
return
}
示例8: do
func (self *Client) do(req *http.Request) (*http.Response, error) {
client := new(http.Client)
// Adding cookie jar
if self.CookieJar != nil {
client.Jar = self.CookieJar
}
// Copying headers
for k := range self.Header {
req.Header.Set(k, self.Header.Get(k))
}
if req.Body == nil {
req.Header.Del("Content-Type")
req.Header.Del("Content-Length")
}
res, err := client.Do(req)
if enableDebug == true {
log.Printf("Fetching %v\n", req.URL.String())
log.Printf("> %s %s", req.Method, req.Proto)
for k := range req.Header {
for kk := range req.Header[k] {
log.Printf("> %s: %s", k, req.Header[k][kk])
}
}
log.Printf("< %s %s", res.Proto, res.Status)
for k := range res.Header {
for kk := range res.Header[k] {
log.Printf("< %s: %s", k, res.Header[k][kk])
}
}
log.Printf("\n")
}
return res, err
}
示例9: DefaultSession
// DefaultSession configures the default rets session
func DefaultSession(user, pwd, userAgent, userAgentPw, retsVersion string, transport http.RoundTripper) (Requester, error) {
if transport == nil {
transport = wirelog.NewHTTPTransport()
}
client := http.Client{
Transport: transport,
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
client.Jar = jar
// 4) send the request
request := func(ctx context.Context, req *http.Request) (*http.Response, error) {
return ctxhttp.Do(ctx, &client, req)
}
// 3) www auth
wwwAuth := (&WWWAuthTransport{
Requester: request,
Username: user,
Password: pwd,
}).Request
// 2) apply ua auth headers per request, if there is a pwd
uaAuth := (&UserAgentAuthentication{
Requester: wwwAuth,
UserAgent: userAgent,
UserAgentPassword: userAgentPw,
GetRETSVersion: CreateRETSVersioner(retsVersion),
GetSessionID: CreateSessionIDer(client.Jar),
}).Request
// 1) apply default headers first (outermost wrapping)
headers := func(ctx context.Context, req *http.Request) (*http.Response, error) {
req.Header.Set(UserAgent, userAgent)
req.Header.Set(RETSVersion, retsVersion)
req.Header.Set(Accept, "*/*")
return uaAuth(ctx, req)
}
return headers, nil
}
示例10: NewArgs
func NewArgs(c *http.Client) *Args {
if c.Jar == nil {
options := cookiejar.Options{
PublicSuffixList: publicsuffix.List,
}
jar, _ := cookiejar.New(&options)
c.Jar = jar
}
return &Args{
Client: c,
Headers: defaultHeaders,
Cookies: nil,
Data: nil,
Params: nil,
Files: nil,
Json: nil,
Proxy: "",
BasicAuth: BasicAuth{},
}
}
示例11: _Init
func (chatter *Chatter) _Init() error {
transport := &http.Transport{
MaxIdleConnsPerHost: 30,
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: time.Minute,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
httpClient := new(http.Client)
chatter.httpClient = httpClient
// NOTE: only livehouse.in using http currently, dont care so far
options := cookiejar.Options{PublicSuffixList: publicsuffix.List}
jar, err := cookiejar.New(&options)
if err != nil {
log.Fatal(err)
return errors.New("Cant create new cookieJar")
}
httpClient.Transport = transport
httpClient.Jar = jar
chatter.LiveUrl = fmt.Sprintf("https://livehouse.in/channel/%s", chatter.ChannelId)
return nil
}
示例12: WebRequest
func WebRequest(queryUrl, method string, params *url.Values, cookies *cookiejar.Jar, headers *map[string]string, referer *string) ([]byte, error) {
if referer == nil {
aux := UrlCommunityBase
referer = &aux
}
client := new(http.Client)
// Create request
var req *http.Request
var err error
switch method {
case "GET":
if params != nil {
if strings.Contains(queryUrl, "?") {
queryUrl = queryUrl + "&"
} else {
queryUrl = queryUrl + "?"
}
queryUrl = queryUrl + params.Encode()
}
req, err = http.NewRequest(method, queryUrl, nil)
if err != nil {
panic("failed to create http request")
}
case "POST":
if params == nil {
params = &url.Values{}
}
req, err = http.NewRequest(method, queryUrl, bytes.NewBufferString(params.Encode()))
if err != nil {
panic("failed to create http request")
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
default:
panic("Only POST and GET requests supported")
}
// Set request header params
req.Header.Set("Accept", "text/javascript, text/html, application/xml, text/xml, */*")
req.Header.Set("User-Agent", "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30")
req.Header.Set("Referer", *referer)
if headers != nil {
for key, val := range *headers {
req.Header.Add(key, val)
}
}
// Set cookies
if cookies != nil {
client.Jar = cookies
}
// Make request
resp, err := client.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("request failed with status code: %v", resp.StatusCode)
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
}
示例13: setHTTPClient
func setHTTPClient(c *http.Client) {
c.Jar = mustInitCookieJar()
c.CheckRedirect = checkRedirect
client = c
}