Skip to content

Commit

Permalink
Removed Content-length from coping
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Dec 13, 2023
1 parent 4ecc45e commit 0787263
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
)

require (
github.com/deckarep/golang-set/v2 v2.5.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set/v2 v2.5.0 h1:hn6cEZtQ0h3J8kFrHR/NrzyOoTnjgW1+FmNJzQ7y/sA=
github.com/deckarep/golang-set/v2 v2.5.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
32 changes: 20 additions & 12 deletions internal/handler/proxy/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@ package proxy

import (
"net/http"
"strings"

mapset "github.com/deckarep/golang-set/v2"
"github.com/go-http-utils/headers"
)

var excluded = mapset.NewSet[string](
headers.Cookie,
headers.SetCookie,
headers.ContentLength,
)

type modificationsMap = map[string]func(string) (string, error)

func noop(s string) (string, error) { return s, nil }

func copyHeaders(source, dest http.Header, modifications modificationsMap) error {
for key, values := range source {
if !strings.EqualFold(key, headers.Cookie) && !strings.EqualFold(key, headers.SetCookie) {
modificationFunc, ok := modifications[headers.Normalize(key)]
if !ok {
modificationFunc = noop
}
if excluded.Contains(key) {
continue
}

for _, value := range values {
modifiedValue, err := modificationFunc(value)
if err != nil {
return err
}
modificationFunc, ok := modifications[headers.Normalize(key)]
if !ok {
modificationFunc = noop
}

dest.Add(key, modifiedValue)
for _, value := range values {
modifiedValue, err := modificationFunc(value)
if err != nil {
return err
}

dest.Add(key, modifiedValue)
}
}

Expand Down

0 comments on commit 0787263

Please sign in to comment.