diff --git a/middleware.go b/middleware.go index a9e73eb803b..7bd88ea5c54 100644 --- a/middleware.go +++ b/middleware.go @@ -1,6 +1,7 @@ package main import ( + "errors" "net/http" "strconv" "time" @@ -124,3 +125,35 @@ func CheckETEnabled(tykMwSuper *TykMiddleware) (used bool) { } return } + +var responseProcessors = map[string]TykResponseHandler{ + "header_injector": HeaderInjector{}, + "response_body_transform": ResponseTransformMiddleware{}, + "header_transform": HeaderTransform{}, +} + +type TykResponseHandler interface { + HandleResponse(http.ResponseWriter, *http.Response, *http.Request, *SessionState) error + New(interface{}, *APISpec) (TykResponseHandler, error) +} + +func GetResponseProcessorByName(name string) (TykResponseHandler, error) { + processor, ok := responseProcessors[name] + if !ok { + return nil, errors.New("Not found") + } + + return processor, nil + +} + +type ResponseChain struct{} + +func (r ResponseChain) Go(chain []TykResponseHandler, rw http.ResponseWriter, res *http.Response, req *http.Request, ses *SessionState) error { + for _, rh := range chain { + if err := rh.HandleResponse(rw, res, req, ses); err != nil { + return err + } + } + return nil +} diff --git a/response_middleware.go b/response_middleware.go deleted file mode 100644 index 8bcbf4aeba6..00000000000 --- a/response_middleware.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "errors" - "net/http" -) - -var responseProcessors = map[string]TykResponseHandler{ - "header_injector": HeaderInjector{}, - "response_body_transform": ResponseTransformMiddleware{}, - "header_transform": HeaderTransform{}, -} - -type TykResponseHandler interface { - HandleResponse(http.ResponseWriter, *http.Response, *http.Request, *SessionState) error - New(interface{}, *APISpec) (TykResponseHandler, error) -} - -func GetResponseProcessorByName(name string) (TykResponseHandler, error) { - processor, ok := responseProcessors[name] - if !ok { - return nil, errors.New("Not found") - } - - return processor, nil - -} - -type ResponseChain struct{} - -func (r ResponseChain) Go(chain []TykResponseHandler, rw http.ResponseWriter, res *http.Response, req *http.Request, ses *SessionState) error { - for _, rh := range chain { - if err := rh.HandleResponse(rw, res, req, ses); err != nil { - return err - } - } - return nil -}