@@ -25,10 +25,10 @@ func NewRequestHeaderInjector(headers []options.Header) (alice.Constructor, erro
2525}
2626
2727func newStripHeaders(headers []options.Header) alice.Constructor {
28− headersToStrip := []string{}
28+ headersToStrip := []options.Header{}
2929 for _, header := range headers {
3030 if !header.PreserveRequestValue {
31− headersToStrip = append(headersToStrip, header.Name)
31+ headersToStrip = append(headersToStrip, header)
3232 }
3333 }
3434
@@ -50,10 +50,10 @@ func flattenHeaders(headers http.Header) {
5050 }
5151}
5252
53−func stripHeaders(headers []string, next http.Handler) http.Handler {
53+func stripHeaders(headers []options.Header, next http.Handler) http.Handler {
5454 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
5555 for _, header := range headers {
56− req.Header.Del(header)
56+ stripNormalizedHeader(req, header)
5757 }
5858 next.ServeHTTP(rw, req)
5959 })
@@ -113,3 +113,32 @@ func injectResponseHeaders(injector header.Injector, next http.Handler) http.Han
113113 next.ServeHTTP(rw, req)
114114 })
115115}
116+
117+// normalizeHeaderName normalizes the header name by lowercasing it
118+// and replacing underscores with hyphens.
119+func normalizeHeaderName(headerName string) string {
120+ headerName = strings.ToLower(headerName)
121+ headerName = strings.ReplaceAll(headerName, "_", "-")
122+ return headerName
123+}
124+
125+// stripNormalizedHeader removes any headers from the request that match
126+// the normalized version of the provided header's name.
127+func stripNormalizedHeader(req *http.Request, header options.Header) {
128+ normalizedName := normalizeHeaderName(header.Name)
129+
130+ toBeDeleted := []string{}
131+ for h := range req.Header {
132+ if normalizeHeaderName(h) == normalizedName {
133+ // necessary to avoid modifying the map while iterating
134+ toBeDeleted = append(toBeDeleted, h)
135+ }
136+ }
137+
138+ for _, h := range toBeDeleted {
139+ // necessary because req.Header.Del accesses the map via
140+ // the header's canonicalized name. We need to delete by
141+ // the original name.
142+ delete(req.Header, h)
143+ }
144+}