From 6a71d71e587357521b2f8002f7c78f79c1c8e609 Mon Sep 17 00:00:00 2001 From: fatedier Date: Sun, 9 Oct 2022 12:13:27 +0800 Subject: [PATCH] improve not found response (#3121) --- .golangci.yml | 1 - pkg/util/vhost/http.go | 2 +- pkg/util/vhost/resource.go | 16 +++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index aefd468..39c8e3f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -48,7 +48,6 @@ linters: - unconvert - unparam - gci - - bodyclose - gosec - asciicheck - prealloc diff --git a/pkg/util/vhost/http.go b/pkg/util/vhost/http.go index f2f0850..846fdca 100644 --- a/pkg/util/vhost/http.go +++ b/pkg/util/vhost/http.go @@ -251,7 +251,7 @@ func (rp *HTTPReverseProxy) connectHandler(rw http.ResponseWriter, req *http.Req remote, err := rp.CreateConnection(domain, url, routeByHTTPUser, remoteAddr) if err != nil { - http.Error(rw, "Failed", http.StatusBadRequest) + _ = notFoundResponse().Write(client) client.Close() return } diff --git a/pkg/util/vhost/resource.go b/pkg/util/vhost/resource.go index 14f6b2a..65bdbcb 100644 --- a/pkg/util/vhost/resource.go +++ b/pkg/util/vhost/resource.go @@ -72,14 +72,16 @@ func notFoundResponse() *http.Response { header.Set("server", "frp/"+version.Full()) header.Set("Content-Type", "text/html") + content := getNotFoundPageContent() res := &http.Response{ - Status: "Not Found", - StatusCode: 404, - Proto: "HTTP/1.0", - ProtoMajor: 1, - ProtoMinor: 0, - Header: header, - Body: io.NopCloser(bytes.NewReader(getNotFoundPageContent())), + Status: "Not Found", + StatusCode: 404, + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + Header: header, + Body: io.NopCloser(bytes.NewReader(content)), + ContentLength: int64(len(content)), } return res }