summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/staticresp.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-20 22:00:54 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-20 22:00:54 -0600
commitb84cb058484e7900d60324da1289d319c77f5447 (patch)
tree23bd14a9f972c672b76bca37251a574622bd3dfe /modules/caddyhttp/staticresp.go
parenta9698728506c580bc38db2e122a5e6ef07f85ce6 (diff)
Fix deferred header ops
Diffstat (limited to 'modules/caddyhttp/staticresp.go')
-rw-r--r--modules/caddyhttp/staticresp.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go
index e07084a..47fae22 100644
--- a/modules/caddyhttp/staticresp.go
+++ b/modules/caddyhttp/staticresp.go
@@ -17,7 +17,7 @@ func init() {
// Static implements a simple responder for static responses.
type Static struct {
- StatusCode int `json:"status_code"`
+ StatusCode int `json:"status_code"` // TODO: should we turn this into a string so that only one field is needed? (string allows replacements)
StatusCodeStr string `json:"status_code_str"`
Headers http.Header `json:"headers"`
Body string `json:"body"`
@@ -30,7 +30,7 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
// close the connection after responding
r.Close = s.Close
- // set all headers, with replacements
+ // set all headers
for field, vals := range s.Headers {
field = repl.ReplaceAll(field, "")
for i := range vals {
@@ -39,7 +39,7 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
w.Header()[field] = vals
}
- // write the headers with a status code
+ // get the status code
statusCode := s.StatusCode
if statusCode == 0 && s.StatusCodeStr != "" {
intVal, err := strconv.Atoi(repl.ReplaceAll(s.StatusCodeStr, ""))
@@ -50,9 +50,11 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
if statusCode == 0 {
statusCode = http.StatusOK
}
+
+ // write headers
w.WriteHeader(statusCode)
- // write the response body, with replacements
+ // write response body
if s.Body != "" {
fmt.Fprint(w, repl.ReplaceAll(s.Body, ""))
}