From 83a8214119eccb39f4c38e7b1ae54daebdeb0184 Mon Sep 17 00:00:00 2001 From: Melonai Date: Mon, 26 Jul 2021 22:37:37 +0200 Subject: Prefer high-level RequestCtx functions over low-level ones --- handlers/passthrough.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'handlers/passthrough.go') 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) } } -- cgit 1.4.1