7 "github.com/justinas/alice"
8 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
9 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/header"
12func NewRequestHeaderInjector(headers []options.Header) (alice.Constructor, error) {
13 headerInjector, err := newRequestHeaderInjector(headers)
15 return nil, fmt.Errorf("error building request header injector: %v", err)
18 strip := newStripHeaders(headers)
20 return alice.New(strip, headerInjector).Then, nil
22 return headerInjector, nil
25func newStripHeaders(headers []options.Header) alice.Constructor {
26 headersToStrip := []string{}
27 for _, header := range headers {
28 if !header.PreserveRequestValue {
29 headersToStrip = append(headersToStrip, header.Name)
33 if len(headersToStrip) == 0 {
37 return func(next http.Handler) http.Handler {
38 return stripHeaders(headersToStrip, next)
42func stripHeaders(headers []string, next http.Handler) http.Handler {
43 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
44 for _, header := range headers {
45 req.Header.Del(header)
47 next.ServeHTTP(rw, req)
51func newRequestHeaderInjector(headers []options.Header) (alice.Constructor, error) {
52 injector, err := header.NewInjector(headers)
54 return nil, fmt.Errorf("error building request injector: %v", err)
57 return func(next http.Handler) http.Handler {
58 return injectRequestHeaders(injector, next)
62func injectRequestHeaders(injector header.Injector, next http.Handler) http.Handler {
63 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
64 scope := GetRequestScope(req)
66 // If scope is nil, this will panic.
67 // A scope should always be injected before this handler is called.
68 injector.Inject(req.Header, scope.Session)
69 next.ServeHTTP(rw, req)
73func NewResponseHeaderInjector(headers []options.Header) (alice.Constructor, error) {
74 headerInjector, err := newResponseHeaderInjector(headers)
76 return nil, fmt.Errorf("error building response header injector: %v", err)
79 return headerInjector, nil
82func newResponseHeaderInjector(headers []options.Header) (alice.Constructor, error) {
83 injector, err := header.NewInjector(headers)
85 return nil, fmt.Errorf("error building response injector: %v", err)
88 return func(next http.Handler) http.Handler {
89 return injectResponseHeaders(injector, next)
93func injectResponseHeaders(injector header.Injector, next http.Handler) http.Handler {
94 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
95 scope := GetRequestScope(req)
97 // If scope is nil, this will panic.
98 // A scope should always be injected before this handler is called.
99 injector.Inject(rw.Header(), scope.Session)
100 next.ServeHTTP(rw, req)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list