Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(500)

Issue 4620049: code review 4620049: http: make Headers be source of truth (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 10 months ago by bradfitz
Modified:
12 years, 10 months ago
Reviewers:
CC:
rsc, golang-dev
Visibility:
Public.

Description

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

Patch Set 1 #

Patch Set 2 : diff -r d086bab9b037 https://go.googlecode.com/hg #

Total comments: 2

Patch Set 3 : diff -r d086bab9b037 https://go.googlecode.com/hg #

Total comments: 8

Patch Set 4 : diff -r bd35e21c471e https://go.googlecode.com/hg #

Patch Set 5 : diff -r f5d2325ee229 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 6 : diff -r f5d2325ee229 https://go.googlecode.com/hg/ #

Patch Set 7 : diff -r f5d2325ee229 https://go.googlecode.com/hg #

Total comments: 3

Patch Set 8 : diff -r f5d2325ee229 https://go.googlecode.com/hg #

Total comments: 1

Patch Set 9 : diff -r f5d2325ee229 https://go.googlecode.com/hg #

Patch Set 10 : diff -r f5d2325ee229 https://go.googlecode.com/hg #

Patch Set 11 : diff -r f5d2325ee229 https://go.googlecode.com/hg #

Patch Set 12 : diff -r f5d2325ee229 https://go.googlecode.com/hg #

Unified diffs Side-by-side diffs Delta from patch set Stats (+314 lines, -225 lines) Patch
M src/cmd/gofix/Makefile View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download
A src/cmd/gofix/httpheaders.go View 1 2 3 4 5 6 7 8 9 1 chunk +66 lines, -0 lines 0 comments Download
A src/cmd/gofix/httpheaders_test.go View 1 2 3 4 5 6 7 1 chunk +73 lines, -0 lines 0 comments Download
M src/cmd/gofix/main.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/http/cgi/child.go View 1 3 chunks +1 line, -10 lines 0 comments Download
M src/pkg/http/cgi/child_test.go View 1 1 chunk +2 lines, -6 lines 0 comments Download
M src/pkg/http/cgi/host.go View 1 2 chunks +5 lines, -13 lines 0 comments Download
M src/pkg/http/client.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/http/client_test.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/http/cookie.go View 1 2 3 4 5 5 chunks +30 lines, -82 lines 0 comments Download
M src/pkg/http/cookie_test.go View 1 2 3 4 6 chunks +55 lines, -38 lines 0 comments Download
M src/pkg/http/readrequest_test.go View 1 2 chunks +1 line, -4 lines 0 comments Download
M src/pkg/http/request.go View 1 2 3 9 chunks +61 lines, -47 lines 0 comments Download
M src/pkg/http/requestwrite_test.go View 1 2 chunks +8 lines, -6 lines 0 comments Download
M src/pkg/http/response.go View 1 2 3 4 4 chunks +5 lines, -9 lines 0 comments Download
M src/pkg/http/reverseproxy.go View 1 1 chunk +0 lines, -4 lines 0 comments Download
M src/pkg/http/reverseproxy_test.go View 1 2 3 4 1 chunk +2 lines, -2 lines 0 comments Download
M src/pkg/http/server.go View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 23
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg
12 years, 10 months ago (2011-06-15 20:14:47 UTC) #1
bradfitz
I'll add a gofix to this CL if/once the rest is cool. On Wed, Jun ...
12 years, 10 months ago (2011-06-15 20:17:49 UTC) #2
gburd
http://codereview.appspot.com/4620049/diff/2001/src/pkg/http/request.go File src/pkg/http/request.go (right): http://codereview.appspot.com/4620049/diff/2001/src/pkg/http/request.go#newcode168 src/pkg/http/request.go:168: return readCookies(r.Header) Because readCookies removes the parsed cookies from ...
12 years, 10 months ago (2011-06-15 20:47:28 UTC) #3
bradfitz
http://codereview.appspot.com/4620049/diff/2001/src/pkg/http/request.go File src/pkg/http/request.go (right): http://codereview.appspot.com/4620049/diff/2001/src/pkg/http/request.go#newcode168 src/pkg/http/request.go:168: return readCookies(r.Header) On 2011/06/15 20:47:28, gburd wrote: > Because ...
12 years, 10 months ago (2011-06-15 20:53:40 UTC) #4
rsc
There's no need for memoization. It's okay for a method to do real work. Russ
12 years, 10 months ago (2011-06-15 21:00:10 UTC) #5
bradfitz
Sure, but there's a line. Cheap-looking accesssors shouldn't be surprisingly expensive. I'm happy punting on ...
12 years, 10 months ago (2011-06-15 21:12:26 UTC) #6
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-15 22:25:50 UTC) #7
rsc
http://codereview.appspot.com/4620049/diff/9001/src/pkg/http/cookie.go File src/pkg/http/cookie.go (right): http://codereview.appspot.com/4620049/diff/9001/src/pkg/http/cookie.go#newcode135 src/pkg/http/cookie.go:135: // TODO(bradfitz): do anything with unparsedLines? Delete. http://codereview.appspot.com/4620049/diff/9001/src/pkg/http/cookie.go#newcode144 src/pkg/http/cookie.go:144: ...
12 years, 10 months ago (2011-06-15 22:34:29 UTC) #8
bradfitz
http://codereview.appspot.com/4620049/diff/9001/src/pkg/http/cookie.go File src/pkg/http/cookie.go (right): http://codereview.appspot.com/4620049/diff/9001/src/pkg/http/cookie.go#newcode144 src/pkg/http/cookie.go:144: // SetCookieValue returns the serialization of the cookie for ...
12 years, 10 months ago (2011-06-15 22:40:37 UTC) #9
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 01:06:11 UTC) #10
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 17:24:26 UTC) #11
rsc
LGTM http://codereview.appspot.com/4620049/diff/16001/src/pkg/http/cookie.go File src/pkg/http/cookie.go (right): http://codereview.appspot.com/4620049/diff/16001/src/pkg/http/cookie.go#newcode146 src/pkg/http/cookie.go:146: func writeSetCookieToBuffer(buf *bytes.Buffer, c *Cookie) { It looks ...
12 years, 10 months ago (2011-06-16 17:36:51 UTC) #12
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 18:59:14 UTC) #13
rsc
The gofix looks good but I am slightly worried about other people's structs having those ...
12 years, 10 months ago (2011-06-16 19:22:40 UTC) #14
rsc
The gofix looks good but I am slightly worried about other people's structs having those ...
12 years, 10 months ago (2011-06-16 19:22:41 UTC) #15
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 19:41:09 UTC) #16
rsc
very close http://codereview.appspot.com/4620049/diff/26001/src/cmd/gofix/httpheaders.go File src/cmd/gofix/httpheaders.go (right): http://codereview.appspot.com/4620049/diff/26001/src/cmd/gofix/httpheaders.go#newcode45 src/cmd/gofix/httpheaders.go:45: if typeof[n] == "string" { I don't ...
12 years, 10 months ago (2011-06-16 19:43:22 UTC) #17
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 19:52:03 UTC) #18
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 19:54:48 UTC) #19
rsc
while you're there, in gofix/main.go: if allowed != nil && !allowed[fix.desc] { s/desc/name/ then the ...
12 years, 10 months ago (2011-06-16 19:56:39 UTC) #20
bradfitz
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 10 months ago (2011-06-16 19:58:55 UTC) #21
rsc
LGTM
12 years, 10 months ago (2011-06-16 20:01:25 UTC) #22
bradfitz
12 years, 10 months ago (2011-06-16 20:02:36 UTC) #23
*** Submitted as http://code.google.com/p/go/source/detail?r=894b438b8564 ***

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
http://codereview.appspot.com/4620049
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b