Skip to content

Commit

Permalink
Merge response_middleware.go into middleware.go
Browse files Browse the repository at this point in the history
The former was tiny and only used in main.go.

Updates TykTechnologies#334.
  • Loading branch information
mvdan authored and buger committed Apr 21, 2017
1 parent fbc32fd commit 67c9e4b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
33 changes: 33 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -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
}
38 changes: 0 additions & 38 deletions response_middleware.go

This file was deleted.

0 comments on commit 67c9e4b

Please sign in to comment.