forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_middleware.go
45 lines (34 loc) · 1018 Bytes
/
response_middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"errors"
"net/http"
)
var RESPONSE_PROCESSORS map[string]TykResponseHandler = 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 := RESPONSE_PROCESSORS[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 {
if chain == nil {
return nil
}
for _, rh := range *chain {
mwErr := rh.HandleResponse(rw, res, req, ses)
if mwErr != nil {
return mwErr
}
}
return nil
}