Skip to content

Commit

Permalink
feat(request): Allow HEAD and OPTIONS request to be intercepted
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan Robert committed Apr 3, 2016
1 parent 1e1f7b4 commit 58123eb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
5 changes: 0 additions & 5 deletions request.go
Expand Up @@ -182,11 +182,6 @@ func Request(h ReqModifierFunc) *RequestInterceptor {
// HandleHTTP handles the middleware call chain, intercepting the request data if possible.
// This methods implements the middleware layer compatible interface.
func (s *RequestInterceptor) HandleHTTP(w http.ResponseWriter, r *http.Request, h http.Handler) {
if r.Method == "HEAD" || r.Method == "OPTIONS" {
h.ServeHTTP(w, r)
return
}

req := NewRequestModifier(r)
s.Modifier(req)
h.ServeHTTP(w, req.Request)
Expand Down
21 changes: 0 additions & 21 deletions request_test.go
Expand Up @@ -350,27 +350,6 @@ func TestRequest(t *testing.T) {
st.Expect(t, intercepted, true)
}

func TestHandleHTTPHEADRequest(t *testing.T) {
testHandleHTTPNotIntercepted(t, "HEAD")
}

func TestHandleHTTPOPTIONSRequest(t *testing.T) {
testHandleHTTPNotIntercepted(t, "OPTIONS")
}

func testHandleHTTPNotIntercepted(t *testing.T, method string) {
interceptor := Request(func(m *RequestModifier) {
m.Header.Set("foo", "bar")
})
stubbedWriter := utils.NewWriterStub()
req := &http.Request{Method: method, Header: make(http.Header)}
handler := http.HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
st.Expect(t, writer, stubbedWriter)
st.Expect(t, r.Header.Get("foo"), "")
})
interceptor.HandleHTTP(stubbedWriter, req, handler)
}

func TestHandleHTTP(t *testing.T) {
interceptor := Request(func(m *RequestModifier) {
m.Header.Set("foo", "bar")
Expand Down

0 comments on commit 58123eb

Please sign in to comment.