Skip to content

Commit

Permalink
improve not found response (fatedier#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier authored Oct 9, 2022
1 parent 6ecc97c commit 6a71d71
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ linters:
- unconvert
- unparam
- gci
- bodyclose
- gosec
- asciicheck
- prealloc
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/vhost/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/util/vhost/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6a71d71

Please sign in to comment.