Modify request header in middleware
<p>Hopefully, this is an easy way to earn some rep. This seems very simple, so I must be doing something wrong and just cant see it.</p>

<p>I have a simple middleware which a transaction id and adds it to the request and response headers.</p>

<pre><code>    func HandleTransactionID(fn http.HandlerFunc) http.HandlerFunc {
    return func(w http.ResponseWriter, req *http.Request) {
        tid := uuid.NewV4()
        req.Header.Set(TransIDHeader, TransIDPrefix + tid.String())
        w.Header().Set(TransIDHeader, TransIDPrefix + tid.String())
        fn(w, req)
    }
}
</code></pre>

<p>In my unit tests, I've confirmed the response header is successfully set, but it doesn't appear the the request header is being set. I would assume that it is possible to modify the request headers, so ?</p>

<pre><code>const (
    WriteTestHeader = "WriterTransHeader"
    RequestTestHeader = "ReqTransHeader"
)


func recorderFunc(w http.ResponseWriter, req *http.Request){
    w.Header().Set(WriteTestHeader, w.Header().Get(TransIDHeader))
    w.Header().Set(RequestTestHeader, req.Header.Get(TransIDHeader))
}

func TestHandleTransactionID(t *testing.T) {
    recorder := httptest.NewRecorder()
    req := httptest.NewRequest("GET", "/foo", nil)
    middleware.HandleTransactionID(recorderFunc)(recorder, req)

    if req.Header.Get(RequestTestHeader) == "" {
        t.Error("request header is nil")
    }
    if recorder.Header().Get(WriteTestHeader) == "" {
        t.Error("response header is nil")
    }
    if req.Header.Get(RequestTestHeader) != recorder.Header().Get(WriteTestHeader) {
        t.Errorf("header value mismatch: %s != %s",
            req.Header.Get(RequestTestHeader),
            recorder.Header().Get(WriteTestHeader))
    }
}
</code></pre>