✨ Add proxy headers into request
All checks were successful
release-nightly / build-docker (push) Successful in 2m26s
All checks were successful
release-nightly / build-docker (push) Successful in 2m26s
This commit is contained in:
parent
28fd5aca8b
commit
11cf35cf0d
20
README.md
20
README.md
@ -5,19 +5,19 @@ A blazing fast reverse proxy with a lot of shining features.
|
||||
## Features
|
||||
|
||||
1. Reverse proxy
|
||||
2. HTTP2 Support
|
||||
3. WebSocket Support
|
||||
4. Static File Hosting
|
||||
5. Low Configuration
|
||||
6. Analytics and Metrics
|
||||
7. Integrate with CI/CD
|
||||
8. Web management panel (Work in progres for v2, available in v1)
|
||||
9. One-liner CLI
|
||||
10. Open-source and free
|
||||
11. **Blazing fast ⚡**
|
||||
2. WebSocket Support
|
||||
3. Static File Hosting
|
||||
4. Low Configuration
|
||||
5. Analytics and Metrics
|
||||
6. Integrate with CI/CD
|
||||
7. Web management panel (Work in progres for v2, available in v1)
|
||||
8. One-liner CLI
|
||||
9. Open-source and free
|
||||
10. **Blazing fast ⚡**
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Currently roadsign haven't supported for server-side events. We are working on it.
|
||||
> At the same time, we don't support HTTP/2.0, [here's](https://github.com/gofiber/fiber/issues/262) the reason
|
||||
|
||||
### How fast is it?
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package hypertext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
@ -94,22 +95,38 @@ func UseProxies(app *fiber.App) {
|
||||
})
|
||||
}
|
||||
|
||||
func makeResponse(ctx *fiber.Ctx, region *navi.Region, location *navi.Location, dest *navi.Destination) error {
|
||||
uri := ctx.Request().URI().String()
|
||||
func makeResponse(c *fiber.Ctx, region *navi.Region, location *navi.Location, dest *navi.Destination) error {
|
||||
uri := c.Request().URI().String()
|
||||
|
||||
// Modify request
|
||||
for _, transformer := range dest.Transformers {
|
||||
if err := transformer.TransformRequest(ctx); err != nil {
|
||||
if err := transformer.TransformRequest(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add reserve proxy headers
|
||||
ip := c.IP()
|
||||
scheme := c.Protocol()
|
||||
protocol := string(c.Request().Header.Protocol())
|
||||
c.Request().Header.Set(fiber.HeaderXForwardedFor, ip)
|
||||
c.Request().Header.Set(fiber.HeaderXForwardedHost, ip)
|
||||
c.Request().Header.Set(fiber.HeaderXForwardedProto, scheme)
|
||||
c.Request().Header.Set(
|
||||
fiber.HeaderVia,
|
||||
fmt.Sprintf("%s %s", protocol, viper.GetString("central")),
|
||||
)
|
||||
c.Request().Header.Set(
|
||||
fiber.HeaderForwarded,
|
||||
fmt.Sprintf("by=%s; for=%s; host=%s; proto=%s", c.IP(), c.IP(), c.Get(fiber.HeaderHost), scheme),
|
||||
)
|
||||
|
||||
// Forward
|
||||
err := navi.R.Forward(ctx, dest)
|
||||
err := navi.R.Forward(c, dest)
|
||||
|
||||
// Modify response
|
||||
for _, transformer := range dest.Transformers {
|
||||
if err := transformer.TransformResponse(ctx); err != nil {
|
||||
if err := transformer.TransformResponse(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -126,10 +143,10 @@ func makeResponse(ctx *fiber.Ctx, region *navi.Region, location *navi.Location,
|
||||
Location: location.ID,
|
||||
Destination: dest.ID,
|
||||
Uri: uri,
|
||||
IpAddress: ctx.IP(),
|
||||
UserAgent: ctx.Get(fiber.HeaderUserAgent),
|
||||
Error: navi.RoadTraceError{
|
||||
IsNull: err == nil,
|
||||
IpAddress: c.IP(),
|
||||
UserAgent: c.Get(fiber.HeaderUserAgent),
|
||||
Error: navi.RoadTraceError{
|
||||
IsNull: err == nil,
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
|
@ -1,3 +1,5 @@
|
||||
id = "central"
|
||||
|
||||
[debug]
|
||||
print_routes = false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user