From bc7b5c8626a8ae7a0c91ffe2c428f80bb77bb104 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 25 Oct 2019 17:04:17 +0800 Subject: [PATCH] fix issue in status checks for static file serving --- .example/net/ghttp/server/static/static.go | 4 +++- net/ghttp/ghttp_server_handler.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.example/net/ghttp/server/static/static.go b/.example/net/ghttp/server/static/static.go index 5512aa705..3fbc63809 100644 --- a/.example/net/ghttp/server/static/static.go +++ b/.example/net/ghttp/server/static/static.go @@ -7,7 +7,9 @@ func main() { s := g.Server() s.SetIndexFolder(true) s.SetServerRoot("/Users/john/Downloads") - s.AddSearchPath("/Users/john/Documents") + //s.AddSearchPath("/Users/john/Documents") + s.SetErrorLogEnabled(true) + s.SetAccessLogEnabled(true) s.SetPort(8199) s.Run() } diff --git a/net/ghttp/ghttp_server_handler.go b/net/ghttp/ghttp_server_handler.go index 587456f6a..998aad231 100644 --- a/net/ghttp/ghttp_server_handler.go +++ b/net/ghttp/ghttp_server_handler.go @@ -140,7 +140,7 @@ func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) { // HTTP status checking. if request.Response.Status == 0 { - if request.Middleware.served || request.Response.buffer.Len() > 0 { + if serveFile != nil || request.Middleware.served || request.Response.buffer.Len() > 0 { request.Response.WriteHeader(http.StatusOK) } else { request.Response.WriteHeader(http.StatusNotFound)