From 7d9f240d5608e8ab1a661dc569aebdb9b8093a2b Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Sat, 18 Jan 2025 22:10:45 +0800 Subject: [PATCH] Updated Close Conn resp for TLS - Use No Resp instead of 200 for close connection mode default site settings --- src/mod/dynamicproxy/Server.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/mod/dynamicproxy/Server.go b/src/mod/dynamicproxy/Server.go index 0922127..c1be285 100644 --- a/src/mod/dynamicproxy/Server.go +++ b/src/mod/dynamicproxy/Server.go @@ -209,25 +209,18 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request) http.Redirect(w, r, redirectTarget, http.StatusTemporaryRedirect) case DefaultSite_NotFoundPage: //Serve the not found page, use template if exists - w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.WriteHeader(http.StatusNotFound) - template, err := os.ReadFile(filepath.Join(h.Parent.Option.WebDirectory, "templates/notfound.html")) - if err != nil { - w.Write(page_hosterror) - } else { - w.Write(template) - } + h.serve404PageWithTemplate(w, r) case DefaultSite_NoResponse: //No response. Just close the connection h.Parent.logRequest(r, false, 444, "root-no_resp", domainOnly) hijacker, ok := w.(http.Hijacker) if !ok { - w.Header().Set("Connection", "close") + w.WriteHeader(http.StatusNoContent) return } conn, _, err := hijacker.Hijack() if err != nil { - w.Header().Set("Connection", "close") + w.WriteHeader(http.StatusNoContent) return } conn.Close() @@ -241,3 +234,15 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request) http.Error(w, "544 - No Route Defined", 544) } } + +// Serve 404 page with template if exists +func (h *ProxyHandler) serve404PageWithTemplate(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.WriteHeader(http.StatusNotFound) + template, err := os.ReadFile(filepath.Join(h.Parent.Option.WebDirectory, "templates/notfound.html")) + if err != nil { + w.Write(page_hosterror) + } else { + w.Write(template) + } +}