From a9698728506c580bc38db2e122a5e6ef07f85ce6 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 20 May 2019 21:21:33 -0600 Subject: Default error handler; rename StaticFiles -> FileServer --- modules/caddyhttp/staticresp.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/caddyhttp/staticresp.go') diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go index 69ec45b..e07084a 100644 --- a/modules/caddyhttp/staticresp.go +++ b/modules/caddyhttp/staticresp.go @@ -3,6 +3,7 @@ package caddyhttp import ( "fmt" "net/http" + "strconv" "bitbucket.org/lightcodelabs/caddy2" ) @@ -16,10 +17,11 @@ func init() { // Static implements a simple responder for static responses. type Static struct { - StatusCode int `json:"status_code"` - Headers http.Header `json:"headers"` - Body string `json:"body"` - Close bool `json:"close"` + StatusCode int `json:"status_code"` + StatusCodeStr string `json:"status_code_str"` + Headers http.Header `json:"headers"` + Body string `json:"body"` + Close bool `json:"close"` } func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error { @@ -39,6 +41,12 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error { // write the headers with a status code statusCode := s.StatusCode + if statusCode == 0 && s.StatusCodeStr != "" { + intVal, err := strconv.Atoi(repl.ReplaceAll(s.StatusCodeStr, "")) + if err == nil { + statusCode = intVal + } + } if statusCode == 0 { statusCode = http.StatusOK } -- cgit v1.2.3