summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/staticresp.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-20 21:21:33 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-20 21:21:33 -0600
commita9698728506c580bc38db2e122a5e6ef07f85ce6 (patch)
treea583112f114fc01e09867aa123578861637b04d5 /modules/caddyhttp/staticresp.go
parentaaacab1bc3790e3a207ae5d70ca6559cac265bff (diff)
Default error handler; rename StaticFiles -> FileServer
Diffstat (limited to 'modules/caddyhttp/staticresp.go')
-rw-r--r--modules/caddyhttp/staticresp.go16
1 files changed, 12 insertions, 4 deletions
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
}