]> Cypherpunks repositories - gostls13.git/commit
net/http/httptest: record trailing headers in ResponseRecorder
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 29 Feb 2016 20:46:48 +0000 (17:46 -0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 8 Mar 2016 19:30:38 +0000 (19:30 +0000)
commitc69e6869c9793872cb0282008ea8ab643a92da65
tree67ff4c3f1d19affc8253e4a3d08e03114b13e8aa
parent4c8589c328ea68ddb551abb4696c20016ed57d99
net/http/httptest: record trailing headers in ResponseRecorder

Trailers() returns the headers that were set by the handler after the
headers were written "to the wire" (in this case HeaderMap) and that
were also specified in a proper header called "Trailer".

Neither HeaderMap or trailerMap (used for Trailers()) are manipulated by
the handler code, instead a third stagingMap is given to the
handler. This avoid a reference kept by handler to affect the recorded
results.

If a handler just modify the header but doesn't call any Write or Flush
method from ResponseWriter (or Flusher) interface, HeaderMap will not be
updated. In this case, calling Flush in the recorder is enough to get
the HeaderMap filled.

Fixes #14531.
Fixes #8857.

Change-Id: I42842341ec3e95c7b87d7e6f178c65cd03d63cc3
Reviewed-on: https://go-review.googlesource.com/20047
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/http/httptest/recorder.go
src/net/http/httptest/recorder_test.go