From 1ffa2bca1641f2ce20d355ce0be7be9f9ea385ea Mon Sep 17 00:00:00 2001 From: "qiying.wang" Date: Tue, 28 Feb 2023 02:13:23 -0800 Subject: [PATCH] Explictly WriteHeader before Write to avoid superfluous response.WriteHeader call --- swagger.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swagger.go b/swagger.go index 5eb250d..ca1b55b 100644 --- a/swagger.go +++ b/swagger.go @@ -173,6 +173,7 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc { switch path { case "index.html": + w.WriteHeader(http.StatusOK) _ = index.Execute(w, config) case "doc.json": doc, err := swag.ReadDoc(config.InstanceName) @@ -181,7 +182,7 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc { return } - + w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte(doc)) case "": http.Redirect(w, r, handler.Prefix+"index.html", http.StatusMovedPermanently)