forked from traefik/traefik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Kubernetes Gateway API RequestHeaderModifier filter
Co-authored-by: Baptiste Mayelle <baptiste.mayelle@traefik.io>
- Loading branch information
1 parent
ac1753a
commit f69fd43
Showing
11 changed files
with
499 additions
and
32 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
package headermodifier | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/traefik/traefik/v3/pkg/config/dynamic" | ||
"github.com/traefik/traefik/v3/pkg/middlewares" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
const typeName = "RequestHeaderModifier" | ||
|
||
// requestHeaderModifier is a middleware used to modify the headers of an HTTP request. | ||
type requestHeaderModifier struct { | ||
next http.Handler | ||
name string | ||
|
||
set map[string]string | ||
add map[string]string | ||
remove []string | ||
} | ||
|
||
// NewRequestHeaderModifier creates a new request header modifier middleware. | ||
func NewRequestHeaderModifier(ctx context.Context, next http.Handler, config dynamic.RequestHeaderModifier, name string) (http.Handler, error) { | ||
logger := middlewares.GetLogger(ctx, name, typeName) | ||
logger.Debug().Msg("Creating middleware") | ||
|
||
return &requestHeaderModifier{ | ||
next: next, | ||
name: name, | ||
set: config.Set, | ||
add: config.Add, | ||
remove: config.Remove, | ||
}, nil | ||
} | ||
|
||
func (r *requestHeaderModifier) GetTracingInformation() (string, string, trace.SpanKind) { | ||
return r.name, typeName, trace.SpanKindUnspecified | ||
} | ||
|
||
func (r *requestHeaderModifier) ServeHTTP(rw http.ResponseWriter, req *http.Request) { | ||
for headerName, headerValue := range r.set { | ||
req.Header.Set(headerName, headerValue) | ||
} | ||
|
||
for headerName, headerValue := range r.add { | ||
req.Header.Add(headerName, headerValue) | ||
} | ||
|
||
for _, headerName := range r.remove { | ||
req.Header.Del(headerName) | ||
} | ||
|
||
r.next.ServeHTTP(rw, req) | ||
} |
Oops, something went wrong.