-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
359183c
commit cc489c6
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// StringSliceVar is a custom type that implements the flag.Value interface | ||
// to store a list of strings. | ||
type StringSliceVar []string | ||
|
||
// String returns a string representation of the StringSliceVar type. | ||
func (ss *StringSliceVar) String() string { | ||
return strings.Join(*ss, ", ") | ||
} | ||
|
||
// Set appends a value to the StringSliceVar. | ||
func (ss *StringSliceVar) Set(value string) error { | ||
*ss = append(*ss, value) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
type headerKey int | ||
|
||
// addHeader adds forwarded headers to the context | ||
func addForwardedHeader(ctx context.Context, h *http.Header, forwardHeaders *StringSliceVar) context.Context { | ||
if forwardHeaders == nil { | ||
return ctx | ||
} | ||
newH := make(http.Header) | ||
for _, fh := range *forwardHeaders { | ||
if values := (*h).Values(fh); values != nil { | ||
for _, v := range values { | ||
newH.Add(fh, v) | ||
} | ||
} | ||
} | ||
return context.WithValue(ctx, headerKey(0), newH) | ||
} | ||
|
||
// getForwardedHeader extracts from context the header | ||
func getForwardedHeader(ctx context.Context) (http.Header, bool) { | ||
if ctxValue := ctx.Value(headerKey(0)); ctxValue != nil { | ||
if header, ok := ctxValue.(http.Header); ok { | ||
return header, true | ||
} | ||
} | ||
return nil, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters