diff --git a/request.go b/request.go index e8cd04b..1d26628 100644 --- a/request.go +++ b/request.go @@ -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) diff --git a/request_test.go b/request_test.go index e1e60da..cd3fed4 100644 --- a/request_test.go +++ b/request_test.go @@ -6,6 +6,7 @@ import ( "encoding/xml" "errors" "github.com/nbio/st" + "gopkg.in/vinci-proxy/utils.v0" "io" "io/ioutil" "net/http" @@ -338,3 +339,29 @@ func TestReaderWithStringReaderAsParameter(t *testing.T) { body, _ := ioutil.ReadAll(req.Body) st.Expect(t, string(body), "Hello") } + +func TestRequest(t *testing.T) { + intercepted := false + modifierFunc := func(m *RequestModifier) { + intercepted = true + } + interceptor := Request(modifierFunc) + interceptor.Modifier(&RequestModifier{}) + st.Expect(t, intercepted, true) +} + +func TestHandleHTTP(t *testing.T) { + interceptor := Request(func(m *RequestModifier) { + m.Header.Set("foo", "bar") + m.String("Hello") + }) + stubbedWriter := utils.NewWriterStub() + req := &http.Request{Method: "POST", 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"), "bar") + requestBody, _ := ioutil.ReadAll(r.Body) + st.Expect(t, string(requestBody), "Hello") + }) + interceptor.HandleHTTP(stubbedWriter, req, handler) +}