• Caio Marcelo de Oliveira Filho's avatar
    net/http/httptest: record trailing headers in ResponseRecorder · c69e6869
    Caio Marcelo de Oliveira Filho authored
    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/20047Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    c69e6869
recorder_test.go 5.57 KB