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

Unified Diff: src/pkg/http/httptest/recorder.go

Issue 4239076: code review 4239076: http: change ResponseWriter.SetHeader(k,v) to Header() ... (Closed)
Patch Set: diff -r a5f4ae5ff5fa https://go.googlecode.com/hg/ Created 13 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/http/fs.go ('k') | src/pkg/http/pprof/pprof.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/http/httptest/recorder.go
===================================================================
--- a/src/pkg/http/httptest/recorder.go
+++ b/src/pkg/http/httptest/recorder.go
@@ -14,11 +14,10 @@
// ResponseRecorder is an implementation of http.ResponseWriter that
// records its mutations for later inspection in tests.
type ResponseRecorder struct {
- Code int // the HTTP response code from WriteHeader
- Header http.Header // if non-nil, the headers to populate
- Body *bytes.Buffer // if non-nil, the bytes.Buffer to append written data to
- Flushed bool
-
+ Code int // the HTTP response code from WriteHeader
+ HeaderMap http.Header // the HTTP response headers
+ Body *bytes.Buffer // if non-nil, the bytes.Buffer to append written data to
+ Flushed bool
FakeRemoteAddr string // the fake RemoteAddr to return, or "" for DefaultRemoteAddr
FakeUsingTLS bool // whether to return true from the UsingTLS method
}
@@ -26,8 +25,8 @@
// NewRecorder returns an initialized ResponseRecorder.
func NewRecorder() *ResponseRecorder {
return &ResponseRecorder{
- Header: http.Header(make(map[string][]string)),
- Body: new(bytes.Buffer),
+ HeaderMap: make(http.Header),
+ Body: new(bytes.Buffer),
}
}
@@ -49,15 +48,9 @@
return rw.FakeUsingTLS
}
-// SetHeader populates rw.Header, if non-nil.
-func (rw *ResponseRecorder) SetHeader(k, v string) {
- if rw.Header != nil {
- if v == "" {
- rw.Header.Del(k)
- } else {
- rw.Header.Set(k, v)
- }
- }
+// Header returns the response headers.
+func (rw *ResponseRecorder) Header() http.Header {
+ return rw.HeaderMap
}
// Write always succeeds and writes to rw.Body, if not nil.
« no previous file with comments | « src/pkg/http/fs.go ('k') | src/pkg/http/pprof/pprof.go » ('j') | no next file with comments »

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