@@ -27,19 +27,19 @@ import (
27
27
"time"
28
28
)
29
29
30
- // A Client is an HTTP client. Its zero value (DefaultClient) is a
31
- // usable client that uses DefaultTransport.
30
+ // A Client is an HTTP client. Its zero value ([ DefaultClient] ) is a
31
+ // usable client that uses [ DefaultTransport] .
32
32
//
33
- // The Client's Transport typically has internal state (cached TCP
33
+ // The [ Client. Transport] typically has internal state (cached TCP
34
34
// connections), so Clients should be reused instead of created as
35
35
// needed. Clients are safe for concurrent use by multiple goroutines.
36
36
//
37
- // A Client is higher-level than a RoundTripper (such as Transport)
37
+ // A Client is higher-level than a [ RoundTripper] (such as [ Transport] )
38
38
// and additionally handles HTTP details such as cookies and
39
39
// redirects.
40
40
//
41
41
// When following redirects, the Client will forward all headers set on the
42
- // initial Request except:
42
+ // initial [ Request] except:
43
43
//
44
44
// - when forwarding sensitive headers like "Authorization",
45
45
// "WWW-Authenticate", and "Cookie" to untrusted targets.
@@ -105,11 +105,11 @@ type Client struct {
105
105
Timeout time.Duration
106
106
}
107
107
108
- // DefaultClient is the default Client and is used by Get, Head, and Post.
108
+ // DefaultClient is the default [ Client] and is used by [ Get], [ Head] , and [ Post] .
109
109
var DefaultClient = & Client {}
110
110
111
111
// RoundTripper is an interface representing the ability to execute a
112
- // single HTTP transaction, obtaining the Response for a given Request.
112
+ // single HTTP transaction, obtaining the [ Response] for a given [ Request] .
113
113
//
114
114
// A RoundTripper must be safe for concurrent use by multiple
115
115
// goroutines.
@@ -439,45 +439,45 @@ func basicAuth(username, password string) string {
439
439
//
440
440
// An error is returned if there were too many redirects or if there
441
441
// was an HTTP protocol error. A non-2xx response doesn't cause an
442
- // error. Any returned error will be of type *url.Error. The url.Error
442
+ // error. Any returned error will be of type [ *url.Error] . The url.Error
443
443
// value's Timeout method will report true if the request timed out.
444
444
//
445
445
// When err is nil, resp always contains a non-nil resp.Body.
446
446
// Caller should close resp.Body when done reading from it.
447
447
//
448
448
// Get is a wrapper around DefaultClient.Get.
449
449
//
450
- // To make a request with custom headers, use NewRequest and
450
+ // To make a request with custom headers, use [ NewRequest] and
451
451
// DefaultClient.Do.
452
452
//
453
- // To make a request with a specified context.Context, use NewRequestWithContext
453
+ // To make a request with a specified context.Context, use [ NewRequestWithContext]
454
454
// and DefaultClient.Do.
455
455
func Get (url string ) (resp * Response , err error ) {
456
456
return DefaultClient .Get (url )
457
457
}
458
458
459
459
// Get issues a GET to the specified URL. If the response is one of the
460
460
// following redirect codes, Get follows the redirect after calling the
461
- // Client's CheckRedirect function:
461
+ // [ Client. CheckRedirect] function:
462
462
//
463
463
// 301 (Moved Permanently)
464
464
// 302 (Found)
465
465
// 303 (See Other)
466
466
// 307 (Temporary Redirect)
467
467
// 308 (Permanent Redirect)
468
468
//
469
- // An error is returned if the Client's CheckRedirect function fails
469
+ // An error is returned if the [ Client. CheckRedirect] function fails
470
470
// or if there was an HTTP protocol error. A non-2xx response doesn't
471
- // cause an error. Any returned error will be of type *url.Error. The
471
+ // cause an error. Any returned error will be of type [ *url.Error] . The
472
472
// url.Error value's Timeout method will report true if the request
473
473
// timed out.
474
474
//
475
475
// When err is nil, resp always contains a non-nil resp.Body.
476
476
// Caller should close resp.Body when done reading from it.
477
477
//
478
- // To make a request with custom headers, use NewRequest and Client.Do.
478
+ // To make a request with custom headers, use [ NewRequest] and [ Client.Do] .
479
479
//
480
- // To make a request with a specified context.Context, use NewRequestWithContext
480
+ // To make a request with a specified context.Context, use [ NewRequestWithContext]
481
481
// and Client.Do.
482
482
func (c * Client ) Get (url string ) (resp * Response , err error ) {
483
483
req , err := NewRequest ("GET" , url , nil )
@@ -558,10 +558,10 @@ func urlErrorOp(method string) string {
558
558
// connectivity problem). A non-2xx status code doesn't cause an
559
559
// error.
560
560
//
561
- // If the returned error is nil, the Response will contain a non-nil
561
+ // If the returned error is nil, the [ Response] will contain a non-nil
562
562
// Body which the user is expected to close. If the Body is not both
563
- // read to EOF and closed, the Client's underlying RoundTripper
564
- // (typically Transport) may not be able to re-use a persistent TCP
563
+ // read to EOF and closed, the [ Client] 's underlying [ RoundTripper]
564
+ // (typically [ Transport] ) may not be able to re-use a persistent TCP
565
565
// connection to the server for a subsequent "keep-alive" request.
566
566
//
567
567
// The request Body, if non-nil, will be closed by the underlying
@@ -570,21 +570,21 @@ func urlErrorOp(method string) string {
570
570
//
571
571
// On error, any Response can be ignored. A non-nil Response with a
572
572
// non-nil error only occurs when CheckRedirect fails, and even then
573
- // the returned Response.Body is already closed.
573
+ // the returned [ Response.Body] is already closed.
574
574
//
575
- // Generally Get, Post, or PostForm will be used instead of Do.
575
+ // Generally [ Get], [ Post] , or [ PostForm] will be used instead of Do.
576
576
//
577
577
// If the server replies with a redirect, the Client first uses the
578
578
// CheckRedirect function to determine whether the redirect should be
579
579
// followed. If permitted, a 301, 302, or 303 redirect causes
580
580
// subsequent requests to use HTTP method GET
581
581
// (or HEAD if the original request was HEAD), with no body.
582
582
// A 307 or 308 redirect preserves the original HTTP method and body,
583
- // provided that the Request.GetBody function is defined.
584
- // The NewRequest function automatically sets GetBody for common
583
+ // provided that the [ Request.GetBody] function is defined.
584
+ // The [ NewRequest] function automatically sets GetBody for common
585
585
// standard library body types.
586
586
//
587
- // Any returned error will be of type *url.Error. The url.Error
587
+ // Any returned error will be of type [ *url.Error] . The url.Error
588
588
// value's Timeout method will report true if the request timed out.
589
589
func (c * Client ) Do (req * Request ) (* Response , error ) {
590
590
return c .do (req )
@@ -818,17 +818,17 @@ func defaultCheckRedirect(req *Request, via []*Request) error {
818
818
//
819
819
// Caller should close resp.Body when done reading from it.
820
820
//
821
- // If the provided body is an io.Closer, it is closed after the
821
+ // If the provided body is an [ io.Closer] , it is closed after the
822
822
// request.
823
823
//
824
824
// Post is a wrapper around DefaultClient.Post.
825
825
//
826
- // To set custom headers, use NewRequest and DefaultClient.Do.
826
+ // To set custom headers, use [ NewRequest] and DefaultClient.Do.
827
827
//
828
- // See the Client.Do method documentation for details on how redirects
828
+ // See the [ Client.Do] method documentation for details on how redirects
829
829
// are handled.
830
830
//
831
- // To make a request with a specified context.Context, use NewRequestWithContext
831
+ // To make a request with a specified context.Context, use [ NewRequestWithContext]
832
832
// and DefaultClient.Do.
833
833
func Post (url , contentType string , body io.Reader ) (resp * Response , err error ) {
834
834
return DefaultClient .Post (url , contentType , body )
@@ -838,13 +838,13 @@ func Post(url, contentType string, body io.Reader) (resp *Response, err error) {
838
838
//
839
839
// Caller should close resp.Body when done reading from it.
840
840
//
841
- // If the provided body is an io.Closer, it is closed after the
841
+ // If the provided body is an [ io.Closer] , it is closed after the
842
842
// request.
843
843
//
844
- // To set custom headers, use NewRequest and Client.Do.
844
+ // To set custom headers, use [ NewRequest] and [ Client.Do] .
845
845
//
846
- // To make a request with a specified context.Context, use NewRequestWithContext
847
- // and Client.Do.
846
+ // To make a request with a specified context.Context, use [ NewRequestWithContext]
847
+ // and [ Client.Do] .
848
848
//
849
849
// See the Client.Do method documentation for details on how redirects
850
850
// are handled.
@@ -861,17 +861,17 @@ func (c *Client) Post(url, contentType string, body io.Reader) (resp *Response,
861
861
// values URL-encoded as the request body.
862
862
//
863
863
// The Content-Type header is set to application/x-www-form-urlencoded.
864
- // To set other headers, use NewRequest and DefaultClient.Do.
864
+ // To set other headers, use [ NewRequest] and DefaultClient.Do.
865
865
//
866
866
// When err is nil, resp always contains a non-nil resp.Body.
867
867
// Caller should close resp.Body when done reading from it.
868
868
//
869
869
// PostForm is a wrapper around DefaultClient.PostForm.
870
870
//
871
- // See the Client.Do method documentation for details on how redirects
871
+ // See the [ Client.Do] method documentation for details on how redirects
872
872
// are handled.
873
873
//
874
- // To make a request with a specified context.Context, use NewRequestWithContext
874
+ // To make a request with a specified [ context.Context] , use [ NewRequestWithContext]
875
875
// and DefaultClient.Do.
876
876
func PostForm (url string , data url.Values ) (resp * Response , err error ) {
877
877
return DefaultClient .PostForm (url , data )
@@ -881,15 +881,15 @@ func PostForm(url string, data url.Values) (resp *Response, err error) {
881
881
// with data's keys and values URL-encoded as the request body.
882
882
//
883
883
// The Content-Type header is set to application/x-www-form-urlencoded.
884
- // To set other headers, use NewRequest and Client.Do.
884
+ // To set other headers, use [ NewRequest] and [ Client.Do] .
885
885
//
886
886
// When err is nil, resp always contains a non-nil resp.Body.
887
887
// Caller should close resp.Body when done reading from it.
888
888
//
889
889
// See the Client.Do method documentation for details on how redirects
890
890
// are handled.
891
891
//
892
- // To make a request with a specified context.Context, use NewRequestWithContext
892
+ // To make a request with a specified context.Context, use [ NewRequestWithContext]
893
893
// and Client.Do.
894
894
func (c * Client ) PostForm (url string , data url.Values ) (resp * Response , err error ) {
895
895
return c .Post (url , "application/x-www-form-urlencoded" , strings .NewReader (data .Encode ()))
@@ -907,24 +907,24 @@ func (c *Client) PostForm(url string, data url.Values) (resp *Response, err erro
907
907
//
908
908
// Head is a wrapper around DefaultClient.Head.
909
909
//
910
- // To make a request with a specified context.Context, use NewRequestWithContext
910
+ // To make a request with a specified [ context.Context] , use [ NewRequestWithContext]
911
911
// and DefaultClient.Do.
912
912
func Head (url string ) (resp * Response , err error ) {
913
913
return DefaultClient .Head (url )
914
914
}
915
915
916
916
// Head issues a HEAD to the specified URL. If the response is one of the
917
917
// following redirect codes, Head follows the redirect after calling the
918
- // Client's CheckRedirect function:
918
+ // [ Client. CheckRedirect] function:
919
919
//
920
920
// 301 (Moved Permanently)
921
921
// 302 (Found)
922
922
// 303 (See Other)
923
923
// 307 (Temporary Redirect)
924
924
// 308 (Permanent Redirect)
925
925
//
926
- // To make a request with a specified context.Context, use NewRequestWithContext
927
- // and Client.Do.
926
+ // To make a request with a specified [ context.Context] , use [ NewRequestWithContext]
927
+ // and [ Client.Do] .
928
928
func (c * Client ) Head (url string ) (resp * Response , err error ) {
929
929
req , err := NewRequest ("HEAD" , url , nil )
930
930
if err != nil {
@@ -933,12 +933,12 @@ func (c *Client) Head(url string) (resp *Response, err error) {
933
933
return c .Do (req )
934
934
}
935
935
936
- // CloseIdleConnections closes any connections on its Transport which
936
+ // CloseIdleConnections closes any connections on its [ Transport] which
937
937
// were previously connected from previous requests but are now
938
938
// sitting idle in a "keep-alive" state. It does not interrupt any
939
939
// connections currently in use.
940
940
//
941
- // If the Client's Transport does not have a CloseIdleConnections method
941
+ // If [ Client. Transport] does not have a [Client. CloseIdleConnections] method
942
942
// then this method does nothing.
943
943
func (c * Client ) CloseIdleConnections () {
944
944
type closeIdler interface {
0 commit comments