Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
core: add x-forwarded-for header
Browse files Browse the repository at this point in the history
  • Loading branch information
h3adex committed Dec 8, 2023
1 parent a4b42c2 commit 3677b4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ full support for all functionalities provided by the Ingress API Object.
- [ ] Https redirect/rewrite
- [ ] Install as a Helm Chart

Find an example of implementing this controller in
[Guardgress-Example](https://github.com/h3adex/guardgress-example).

## Images
- [ghcr.io/h3adex/guardgress:latest](https://github.com/h3adex/guardgress/pkgs/container/guardgress)

Expand Down
10 changes: 8 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func (s Server) ServeHttps(ctx *gin.Context) {
return
}

ctx.Header("Access-Control-Allow-Origin", "*")
req, err := httputil.DumpRequest(ctx.Request, true)
log.Debug("request coming from ip: ", ctx.ClientIP())
log.Debug("request dump: ", string(req))

svcUrl, parsedAnnotations, routingError := s.RoutingTable.GetBackend(
ctx.Request.Host,
ctx.Request.RequestURI,
Expand Down Expand Up @@ -149,6 +152,7 @@ func (s Server) ServeHttps(ctx *gin.Context) {
}
}

ctx.Request.Header.Add("X-Forwarded-For", ctx.ClientIP())
proxy.Director = func(req *http.Request) {
req.Header = ctx.Request.Header
req.Host = ctx.Request.Host
Expand All @@ -166,7 +170,8 @@ func (s Server) ServeHTTP(ctx *gin.Context) {
return
}

ctx.Header("Access-Control-Allow-Origin", "*")
log.Debug("request coming from ip: ", ctx.ClientIP())

svcUrl, _, routingError := s.RoutingTable.GetBackend(
ctx.Request.Host,
ctx.Request.RequestURI,
Expand All @@ -188,6 +193,7 @@ func (s Server) ServeHTTP(ctx *gin.Context) {
}
}

ctx.Request.Header.Add("X-Forwarded-For", ctx.ClientIP())
proxy.Director = func(req *http.Request) {
req.Header = ctx.Request.Header
req.Host = ctx.Request.Host
Expand Down

0 comments on commit 3677b4b

Please sign in to comment.