summary refs log tree commit diff
path: root/handlers/passthrough.go
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-07-26 22:37:37 +0200
committerMelonai <einebeere@gmail.com>2021-07-26 22:37:37 +0200
commit83a8214119eccb39f4c38e7b1ae54daebdeb0184 (patch)
tree064be9c76e295985634718cb290d8acb1cd2dada /handlers/passthrough.go
parent0ac82c133b78a14239beb9034380c44d95d4bad3 (diff)
downloadportgate-83a8214119eccb39f4c38e7b1ae54daebdeb0184.tar.zst
portgate-83a8214119eccb39f4c38e7b1ae54daebdeb0184.zip
Prefer high-level RequestCtx functions over low-level ones
Diffstat (limited to 'handlers/passthrough.go')
-rw-r--r--handlers/passthrough.go6
1 files changed, 2 insertions, 4 deletions
diff --git a/handlers/passthrough.go b/handlers/passthrough.go
index f322d3a..b2daa88 100644
--- a/handlers/passthrough.go
+++ b/handlers/passthrough.go
@@ -2,7 +2,6 @@ package handlers
 
 import (
 	"github.com/valyala/fasthttp"
-	"net/http"
 	"portgate"
 )
 
@@ -16,14 +15,13 @@ func (h *RequestHandler) handlePassthroughRequest(ctx *fasthttp.RequestCtx, p po
 	// We reuse the request given to us by the user with minor changes to route it to the
 	// destination host.
 	ctx.Request.SetRequestURI(h.config.MakeUrl(p))
-	ctx.Request.Header.Set("Host", h.config.TargetAddress(p.DestinationIdentifier))
+	ctx.Request.Header.SetHost(h.config.TargetAddress(p.DestinationIdentifier))
 
 	// We pipe the response given to us by the destination host back to the user.
 	// Since it's possible that we get a redirect, we take this into account,
 	// but only allow upto 10 redirects.
 	err := h.client.DoRedirects(&ctx.Request, &ctx.Response, 10)
 	if err != nil {
-		ctx.SetStatusCode(http.StatusInternalServerError)
-		_, _ = ctx.WriteString("An error occurred.")
+		h.handleError(ctx)
 	}
 }