mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
http: make Headers be source of truth
Previously Request and Response had redundant fields for Referer, UserAgent, and cookies which caused confusion and bugs. It also didn't allow us to expand the package over time, since the way to access fields would be in the Headers one day and promoted to a field the next day. That would be hard to gofix, especially with code ranging over Headers. After a discussion on the mail package's design with a similar problem, we've designed to make the Headers be the source of truth and add accessors instead. Request: change: Referer -> Referer() change: UserAgent -> UserAgent() change: Cookie -> Cookies() new: Cookie(name) *Cookie new: AddCookie(*Cookie) Response: change: Cookie -> Cookies() Cookie: new: String() string R=rsc CC=golang-dev https://golang.org/cl/4620049
This commit is contained in:
parent
7f3e109d2f
commit
6e9b1a78ff
18 changed files with 314 additions and 225 deletions
|
|
@ -49,10 +49,10 @@ func TestReverseProxy(t *testing.T) {
|
|||
if g, e := res.Header.Get("X-Foo"), "bar"; g != e {
|
||||
t.Errorf("got X-Foo %q; expected %q", g, e)
|
||||
}
|
||||
if g, e := len(res.SetCookie), 1; g != e {
|
||||
if g, e := len(res.Header["Set-Cookie"]), 1; g != e {
|
||||
t.Fatalf("got %d SetCookies, want %d", g, e)
|
||||
}
|
||||
if cookie := res.SetCookie[0]; cookie.Name != "flavor" {
|
||||
if cookie := res.Cookies()[0]; cookie.Name != "flavor" {
|
||||
t.Errorf("unexpected cookie %q", cookie.Name)
|
||||
}
|
||||
bodyBytes, _ := ioutil.ReadAll(res.Body)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue