Commit 415da714 authored by Benoit Sigoure's avatar Benoit Sigoure Committed by Brad Fitzpatrick

net/http: document that Basic Auth may require URL encoding

Explicitly warn callers that no URL encoding is performed and
that they might need to do it.

Fixes #31577

Change-Id: I52dc3fd2798ba8c3652d4a967b1c5c48eb69f43b
Reviewed-on: https://go-review.googlesource.com/c/go/+/173319Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 1f0c102a
...@@ -912,6 +912,10 @@ func parseBasicAuth(auth string) (username, password string, ok bool) { ...@@ -912,6 +912,10 @@ func parseBasicAuth(auth string) (username, password string, ok bool) {
// //
// With HTTP Basic Authentication the provided username and password // With HTTP Basic Authentication the provided username and password
// are not encrypted. // are not encrypted.
//
// Some protocols may impose additional requirements on pre-escaping the
// username and password. For instance, when used with OAuth2, both arguments
// must be URL encoded first with url.QueryEscape.
func (r *Request) SetBasicAuth(username, password string) { func (r *Request) SetBasicAuth(username, password string) {
r.Header.Set("Authorization", "Basic "+basicAuth(username, password)) r.Header.Set("Authorization", "Basic "+basicAuth(username, password))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment