2010-12-03 05:34:57 +01:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2011-11-30 00:02:54 +01:00
|
|
|
// HTTP client. See RFC 2616.
|
2012-11-21 08:03:38 +01:00
|
|
|
//
|
2011-11-30 00:02:54 +01:00
|
|
|
// This is the high-level Client interface.
|
|
|
|
// The low-level implementation is in transport.go.
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2011-12-03 03:17:34 +01:00
|
|
|
"errors"
|
2010-12-03 05:34:57 +01:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2012-10-03 07:27:36 +02:00
|
|
|
"log"
|
2011-12-07 02:11:29 +01:00
|
|
|
"net/url"
|
2010-12-03 05:34:57 +01:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
// A Client is an HTTP client. Its zero value (DefaultClient) is a
|
|
|
|
// usable client that uses DefaultTransport.
|
2011-09-16 17:47:21 +02:00
|
|
|
//
|
2013-07-16 08:54:42 +02:00
|
|
|
// The Client's Transport typically has internal state (cached TCP
|
|
|
|
// connections), so Clients should be reused instead of created as
|
2011-09-16 17:47:21 +02:00
|
|
|
// needed. Clients are safe for concurrent use by multiple goroutines.
|
2013-07-16 08:54:42 +02:00
|
|
|
//
|
|
|
|
// A Client is higher-level than a RoundTripper (such as Transport)
|
|
|
|
// and additionally handles HTTP details such as cookies and
|
|
|
|
// redirects.
|
2011-03-17 00:05:44 +01:00
|
|
|
type Client struct {
|
2012-01-25 22:54:22 +01:00
|
|
|
// Transport specifies the mechanism by which individual
|
|
|
|
// HTTP requests are made.
|
|
|
|
// If nil, DefaultTransport is used.
|
|
|
|
Transport RoundTripper
|
2011-05-20 02:18:15 +02:00
|
|
|
|
2012-01-25 22:54:22 +01:00
|
|
|
// CheckRedirect specifies the policy for handling redirects.
|
2011-05-20 02:18:15 +02:00
|
|
|
// If CheckRedirect is not nil, the client calls it before
|
2012-10-23 06:31:11 +02:00
|
|
|
// following an HTTP redirect. The arguments req and via are
|
|
|
|
// the upcoming request and the requests made already, oldest
|
|
|
|
// first. If CheckRedirect returns an error, the Client's Get
|
|
|
|
// method returns both the previous Response and
|
|
|
|
// CheckRedirect's error (wrapped in a url.Error) instead of
|
2012-10-03 07:27:36 +02:00
|
|
|
// issuing the Request req.
|
2011-05-20 02:18:15 +02:00
|
|
|
//
|
|
|
|
// If CheckRedirect is nil, the Client uses its default policy,
|
|
|
|
// which is to stop after 10 consecutive requests.
|
2011-12-03 03:17:34 +01:00
|
|
|
CheckRedirect func(req *Request, via []*Request) error
|
2012-01-13 06:11:45 +01:00
|
|
|
|
2012-11-21 08:03:38 +01:00
|
|
|
// Jar specifies the cookie jar.
|
|
|
|
// If Jar is nil, cookies are not sent in requests and ignored
|
2012-01-13 06:11:45 +01:00
|
|
|
// in responses.
|
|
|
|
Jar CookieJar
|
2011-03-17 00:05:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultClient is the default Client and is used by Get, Head, and Post.
|
|
|
|
var DefaultClient = &Client{}
|
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
// RoundTripper is an interface representing the ability to execute a
|
2011-03-17 00:05:44 +01:00
|
|
|
// single HTTP transaction, obtaining the Response for a given Request.
|
2011-09-16 17:47:21 +02:00
|
|
|
//
|
|
|
|
// A RoundTripper must be safe for concurrent use by multiple
|
|
|
|
// goroutines.
|
2011-03-25 00:46:17 +01:00
|
|
|
type RoundTripper interface {
|
|
|
|
// RoundTrip executes a single HTTP transaction, returning
|
|
|
|
// the Response for the request req. RoundTrip should not
|
|
|
|
// attempt to interpret the response. In particular,
|
|
|
|
// RoundTrip must return err == nil if it obtained a response,
|
|
|
|
// regardless of the response's HTTP status code. A non-nil
|
|
|
|
// err should be reserved for failure to obtain a response.
|
|
|
|
// Similarly, RoundTrip should not attempt to handle
|
|
|
|
// higher-level protocol details such as redirects,
|
2011-03-17 00:05:44 +01:00
|
|
|
// authentication, or cookies.
|
|
|
|
//
|
2011-10-27 01:57:58 +02:00
|
|
|
// RoundTrip should not modify the request, except for
|
|
|
|
// consuming the Body. The request's URL and Header fields
|
|
|
|
// are guaranteed to be initialized.
|
2011-12-03 03:17:34 +01:00
|
|
|
RoundTrip(*Request) (*Response, error)
|
2011-03-17 00:05:44 +01:00
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
|
|
|
|
// return true if the string includes a port.
|
|
|
|
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
|
|
|
|
|
|
|
|
// Used in Send to implement io.ReadCloser by bundling together the
|
|
|
|
// bufio.Reader through which we read the response, and the underlying
|
|
|
|
// network connection.
|
|
|
|
type readClose struct {
|
|
|
|
io.Reader
|
|
|
|
io.Closer
|
|
|
|
}
|
|
|
|
|
2012-11-21 08:03:38 +01:00
|
|
|
func (c *Client) send(req *Request) (*Response, error) {
|
|
|
|
if c.Jar != nil {
|
|
|
|
for _, cookie := range c.Jar.Cookies(req.URL) {
|
|
|
|
req.AddCookie(cookie)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp, err := send(req, c.Transport)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if c.Jar != nil {
|
2012-12-22 02:15:33 +01:00
|
|
|
if rc := resp.Cookies(); len(rc) > 0 {
|
|
|
|
c.Jar.SetCookies(req.URL, rc)
|
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2011-03-17 00:05:44 +01:00
|
|
|
// Do sends an HTTP request and returns an HTTP response, following
|
|
|
|
// policy (e.g. redirects, cookies, auth) as configured on the client.
|
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// An error is returned if caused by client policy (such as
|
|
|
|
// CheckRedirect), or if there was an HTTP protocol error.
|
|
|
|
// A non-2xx response doesn't cause an error.
|
2011-10-27 01:57:58 +02:00
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// When err is nil, resp always contains a non-nil resp.Body.
|
|
|
|
//
|
2012-10-23 06:31:11 +02:00
|
|
|
// Callers should close resp.Body when done reading from it. If
|
2011-10-27 01:57:58 +02:00
|
|
|
// resp.Body is not closed, the Client's underlying RoundTripper
|
|
|
|
// (typically Transport) may not be able to re-use a persistent TCP
|
|
|
|
// connection to the server for a subsequent "keep-alive" request.
|
2011-03-17 00:05:44 +01:00
|
|
|
//
|
|
|
|
// Generally Get, Post, or PostForm will be used instead of Do.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (c *Client) Do(req *Request) (resp *Response, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if req.Method == "GET" || req.Method == "HEAD" {
|
2012-12-22 02:15:33 +01:00
|
|
|
return c.doFollowingRedirects(req, shouldRedirectGet)
|
|
|
|
}
|
|
|
|
if req.Method == "POST" || req.Method == "PUT" {
|
|
|
|
return c.doFollowingRedirects(req, shouldRedirectPost)
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
return c.send(req)
|
2011-03-17 00:05:44 +01:00
|
|
|
}
|
|
|
|
|
2012-10-03 07:27:36 +02:00
|
|
|
// send issues an HTTP request.
|
|
|
|
// Caller should close resp.Body when done reading from it.
|
2011-12-03 03:17:34 +01:00
|
|
|
func send(req *Request, t RoundTripper) (resp *Response, err error) {
|
2011-03-17 00:05:44 +01:00
|
|
|
if t == nil {
|
|
|
|
t = DefaultTransport
|
|
|
|
if t == nil {
|
2011-12-03 03:17:34 +01:00
|
|
|
err = errors.New("http: no Client.Transport or DefaultTransport")
|
2011-03-17 00:05:44 +01:00
|
|
|
return
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
if req.URL == nil {
|
2011-12-03 03:17:34 +01:00
|
|
|
return nil, errors.New("http: nil Request.URL")
|
2011-10-27 01:57:58 +02:00
|
|
|
}
|
|
|
|
|
2012-02-01 20:26:59 +01:00
|
|
|
if req.RequestURI != "" {
|
|
|
|
return nil, errors.New("http: Request.RequestURI can't be set in client requests.")
|
|
|
|
}
|
|
|
|
|
2011-03-17 00:05:44 +01:00
|
|
|
// Most the callers of send (Get, Post, et al) don't need
|
|
|
|
// Headers, leaving it uninitialized. We guarantee to the
|
2011-03-25 00:46:17 +01:00
|
|
|
// Transport that this has been initialized, though.
|
2011-03-17 00:05:44 +01:00
|
|
|
if req.Header == nil {
|
2011-03-25 00:46:17 +01:00
|
|
|
req.Header = make(Header)
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2011-03-17 00:05:44 +01:00
|
|
|
|
2012-01-25 22:54:22 +01:00
|
|
|
if u := req.URL.User; u != nil {
|
|
|
|
req.Header.Set("Authorization", "Basic "+base64.URLEncoding.EncodeToString([]byte(u.String())))
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2012-10-03 07:27:36 +02:00
|
|
|
resp, err = t.RoundTrip(req)
|
|
|
|
if err != nil {
|
|
|
|
if resp != nil {
|
|
|
|
log.Printf("RoundTripper returned a response & error; ignoring response")
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// True if the specified HTTP status code is one for which the Get utility should
|
|
|
|
// automatically redirect.
|
2012-12-22 02:15:33 +01:00
|
|
|
func shouldRedirectGet(statusCode int) bool {
|
2010-12-03 05:34:57 +01:00
|
|
|
switch statusCode {
|
|
|
|
case StatusMovedPermanently, StatusFound, StatusSeeOther, StatusTemporaryRedirect:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// True if the specified HTTP status code is one for which the Post utility should
|
|
|
|
// automatically redirect.
|
|
|
|
func shouldRedirectPost(statusCode int) bool {
|
|
|
|
switch statusCode {
|
|
|
|
case StatusFound, StatusSeeOther:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
// Get issues a GET to the specified URL. If the response is one of the following
|
2011-05-20 02:18:15 +02:00
|
|
|
// redirect codes, Get follows the redirect, up to a maximum of 10 redirects:
|
2010-12-03 05:34:57 +01:00
|
|
|
//
|
|
|
|
// 301 (Moved Permanently)
|
|
|
|
// 302 (Found)
|
|
|
|
// 303 (See Other)
|
|
|
|
// 307 (Temporary Redirect)
|
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// An error is returned if there were too many redirects or if there
|
|
|
|
// was an HTTP protocol error. A non-2xx response doesn't cause an
|
|
|
|
// error.
|
|
|
|
//
|
|
|
|
// When err is nil, resp always contains a non-nil resp.Body.
|
|
|
|
// Caller should close resp.Body when done reading from it.
|
2011-03-17 00:05:44 +01:00
|
|
|
//
|
2011-12-07 02:11:29 +01:00
|
|
|
// Get is a wrapper around DefaultClient.Get.
|
2012-10-03 07:27:36 +02:00
|
|
|
func Get(url string) (resp *Response, err error) {
|
2011-03-17 00:05:44 +01:00
|
|
|
return DefaultClient.Get(url)
|
|
|
|
}
|
|
|
|
|
2011-05-20 02:18:15 +02:00
|
|
|
// Get issues a GET to the specified URL. If the response is one of the
|
|
|
|
// following redirect codes, Get follows the redirect after calling the
|
|
|
|
// Client's CheckRedirect function.
|
2011-03-17 00:05:44 +01:00
|
|
|
//
|
|
|
|
// 301 (Moved Permanently)
|
|
|
|
// 302 (Found)
|
|
|
|
// 303 (See Other)
|
|
|
|
// 307 (Temporary Redirect)
|
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// An error is returned if the Client's CheckRedirect function fails
|
|
|
|
// or if there was an HTTP protocol error. A non-2xx response doesn't
|
|
|
|
// cause an error.
|
|
|
|
//
|
|
|
|
// When err is nil, resp always contains a non-nil resp.Body.
|
|
|
|
// Caller should close resp.Body when done reading from it.
|
|
|
|
func (c *Client) Get(url string) (resp *Response, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
req, err := NewRequest("GET", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2012-12-22 02:15:33 +01:00
|
|
|
return c.doFollowingRedirects(req, shouldRedirectGet)
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
func (c *Client) doFollowingRedirects(ireq *Request, shouldRedirect func(int) bool) (resp *Response, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
var base *url.URL
|
2011-05-20 02:18:15 +02:00
|
|
|
redirectChecker := c.CheckRedirect
|
|
|
|
if redirectChecker == nil {
|
|
|
|
redirectChecker = defaultCheckRedirect
|
|
|
|
}
|
|
|
|
var via []*Request
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
if ireq.URL == nil {
|
2011-12-03 03:17:34 +01:00
|
|
|
return nil, errors.New("http: nil Request.URL")
|
2011-10-27 01:57:58 +02:00
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
req := ireq
|
|
|
|
urlStr := "" // next relative or absolute URL to fetch (after first request)
|
2012-10-23 06:31:11 +02:00
|
|
|
redirectFailed := false
|
2011-05-20 02:18:15 +02:00
|
|
|
for redirect := 0; ; redirect++ {
|
2011-09-16 17:47:21 +02:00
|
|
|
if redirect != 0 {
|
|
|
|
req = new(Request)
|
|
|
|
req.Method = ireq.Method
|
2012-12-22 02:15:33 +01:00
|
|
|
if ireq.Method == "POST" || ireq.Method == "PUT" {
|
|
|
|
req.Method = "GET"
|
|
|
|
}
|
2011-09-16 17:47:21 +02:00
|
|
|
req.Header = make(Header)
|
|
|
|
req.URL, err = base.Parse(urlStr)
|
2011-05-20 02:18:15 +02:00
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2011-09-16 17:47:21 +02:00
|
|
|
if len(via) > 0 {
|
|
|
|
// Add the Referer header.
|
|
|
|
lastReq := via[len(via)-1]
|
|
|
|
if lastReq.URL.Scheme != "https" {
|
|
|
|
req.Header.Set("Referer", lastReq.URL.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = redirectChecker(req, via)
|
|
|
|
if err != nil {
|
2012-10-23 06:31:11 +02:00
|
|
|
redirectFailed = true
|
2011-09-16 17:47:21 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 02:18:15 +02:00
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
urlStr = req.URL.String()
|
2012-11-21 08:03:38 +01:00
|
|
|
if resp, err = c.send(req); err != nil {
|
2010-12-03 05:34:57 +01:00
|
|
|
break
|
|
|
|
}
|
2012-01-13 06:11:45 +01:00
|
|
|
|
2012-10-03 07:27:36 +02:00
|
|
|
if shouldRedirect(resp.StatusCode) {
|
|
|
|
resp.Body.Close()
|
|
|
|
if urlStr = resp.Header.Get("Location"); urlStr == "" {
|
|
|
|
err = errors.New(fmt.Sprintf("%d response missing Location header", resp.StatusCode))
|
2010-12-03 05:34:57 +01:00
|
|
|
break
|
|
|
|
}
|
2011-01-21 19:19:03 +01:00
|
|
|
base = req.URL
|
2011-09-16 17:47:21 +02:00
|
|
|
via = append(via, req)
|
2010-12-03 05:34:57 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
method := ireq.Method
|
2012-10-23 06:31:11 +02:00
|
|
|
urlErr := &url.Error{
|
2012-02-09 09:19:58 +01:00
|
|
|
Op: method[0:1] + strings.ToLower(method[1:]),
|
|
|
|
URL: urlStr,
|
|
|
|
Err: err,
|
|
|
|
}
|
2012-10-23 06:31:11 +02:00
|
|
|
|
|
|
|
if redirectFailed {
|
|
|
|
// Special case for Go 1 compatibility: return both the response
|
|
|
|
// and an error if the CheckRedirect function failed.
|
|
|
|
// See http://golang.org/issue/3795
|
|
|
|
return resp, urlErr
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp != nil {
|
|
|
|
resp.Body.Close()
|
|
|
|
}
|
|
|
|
return nil, urlErr
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
func defaultCheckRedirect(req *Request, via []*Request) error {
|
2011-05-20 02:18:15 +02:00
|
|
|
if len(via) >= 10 {
|
2011-12-03 03:17:34 +01:00
|
|
|
return errors.New("stopped after 10 redirects")
|
2011-05-20 02:18:15 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
// Post issues a POST to the specified URL.
|
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// Caller should close resp.Body when done reading from it.
|
2011-03-17 00:05:44 +01:00
|
|
|
//
|
|
|
|
// Post is a wrapper around DefaultClient.Post
|
2012-10-03 07:27:36 +02:00
|
|
|
func Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
|
2011-03-17 00:05:44 +01:00
|
|
|
return DefaultClient.Post(url, bodyType, body)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Post issues a POST to the specified URL.
|
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// Caller should close resp.Body when done reading from it.
|
|
|
|
func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
req, err := NewRequest("POST", url, body)
|
2010-12-03 05:34:57 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-09-16 17:47:21 +02:00
|
|
|
req.Header.Set("Content-Type", bodyType)
|
2012-12-22 02:15:33 +01:00
|
|
|
return c.doFollowingRedirects(req, shouldRedirectPost)
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2012-10-03 07:27:36 +02:00
|
|
|
// PostForm issues a POST to the specified URL, with data's keys and
|
|
|
|
// values URL-encoded as the request body.
|
2010-12-03 05:34:57 +01:00
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// When err is nil, resp always contains a non-nil resp.Body.
|
|
|
|
// Caller should close resp.Body when done reading from it.
|
2011-03-17 00:05:44 +01:00
|
|
|
//
|
|
|
|
// PostForm is a wrapper around DefaultClient.PostForm
|
2012-10-03 07:27:36 +02:00
|
|
|
func PostForm(url string, data url.Values) (resp *Response, err error) {
|
2011-03-17 00:05:44 +01:00
|
|
|
return DefaultClient.PostForm(url, data)
|
|
|
|
}
|
|
|
|
|
2012-11-21 08:03:38 +01:00
|
|
|
// PostForm issues a POST to the specified URL,
|
2011-03-17 00:05:44 +01:00
|
|
|
// with data's keys and values urlencoded as the request body.
|
|
|
|
//
|
2012-10-03 07:27:36 +02:00
|
|
|
// When err is nil, resp always contains a non-nil resp.Body.
|
|
|
|
// Caller should close resp.Body when done reading from it.
|
|
|
|
func (c *Client) PostForm(url string, data url.Values) (resp *Response, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
// Head issues a HEAD to the specified URL. If the response is one of the
|
|
|
|
// following redirect codes, Head follows the redirect after calling the
|
|
|
|
// Client's CheckRedirect function.
|
|
|
|
//
|
|
|
|
// 301 (Moved Permanently)
|
|
|
|
// 302 (Found)
|
|
|
|
// 303 (See Other)
|
|
|
|
// 307 (Temporary Redirect)
|
2011-03-17 00:05:44 +01:00
|
|
|
//
|
|
|
|
// Head is a wrapper around DefaultClient.Head
|
2012-10-03 07:27:36 +02:00
|
|
|
func Head(url string) (resp *Response, err error) {
|
2011-03-17 00:05:44 +01:00
|
|
|
return DefaultClient.Head(url)
|
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
// Head issues a HEAD to the specified URL. If the response is one of the
|
|
|
|
// following redirect codes, Head follows the redirect after calling the
|
|
|
|
// Client's CheckRedirect function.
|
|
|
|
//
|
|
|
|
// 301 (Moved Permanently)
|
|
|
|
// 302 (Found)
|
|
|
|
// 303 (See Other)
|
|
|
|
// 307 (Temporary Redirect)
|
2012-10-03 07:27:36 +02:00
|
|
|
func (c *Client) Head(url string) (resp *Response, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
req, err := NewRequest("HEAD", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2012-12-22 02:15:33 +01:00
|
|
|
return c.doFollowingRedirects(req, shouldRedirectGet)
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|