summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/staticresp.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-07-11 17:07:52 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-07-11 17:07:52 -0600
commit4698352b20872557e624c54c1b4a1e0074f0baca (patch)
treeac1c77bccd7a1d23cb8e1fd361ed334a3890a80c /modules/caddyhttp/staticresp.go
parent9343403358bd34b787a209b41c5b820781f78890 (diff)
parenteb8625f7744ba5e72b51549adc086e45313267cb (diff)
Merge branch 'v2-handlers' into v2
# Conflicts: # modules/caddyhttp/caddyhttp.go # modules/caddyhttp/fileserver/staticfiles.go # modules/caddyhttp/routes.go # modules/caddyhttp/server.go # modules/caddyhttp/staticresp.go # modules/caddyhttp/staticresp_test.go
Diffstat (limited to 'modules/caddyhttp/staticresp.go')
-rw-r--r--modules/caddyhttp/staticresp.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go
index 8e4a3df..291d992 100644
--- a/modules/caddyhttp/staticresp.go
+++ b/modules/caddyhttp/staticresp.go
@@ -24,20 +24,20 @@ import (
func init() {
caddy.RegisterModule(caddy.Module{
- Name: "http.handlers.static",
- New: func() interface{} { return new(Static) },
+ Name: "http.handlers.static_response",
+ New: func() interface{} { return new(StaticResponse) },
})
}
-// Static implements a simple responder for static responses.
-type Static struct {
- StatusCode string `json:"status_code"`
+// StaticResponse implements a simple responder for static responses.
+type StaticResponse struct {
+ StatusCode weakString `json:"status_code"`
Headers http.Header `json:"headers"`
Body string `json:"body"`
Close bool `json:"close"`
}
-func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Handler) error {
+func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Handler) error {
repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer)
// close the connection after responding
@@ -60,11 +60,12 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Handler) err
// get the status code
statusCode := http.StatusOK
- if s.StatusCode != "" {
- intVal, err := strconv.Atoi(repl.ReplaceAll(s.StatusCode, ""))
- if err == nil {
- statusCode = intVal
+ if codeStr := s.StatusCode.String(); codeStr != "" {
+ intVal, err := strconv.Atoi(repl.ReplaceAll(codeStr, ""))
+ if err != nil {
+ return Error(http.StatusInternalServerError, err)
}
+ statusCode = intVal
}
// write headers
@@ -79,4 +80,4 @@ func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Handler) err
}
// Interface guard
-var _ MiddlewareHandler = (*Static)(nil)
+var _ MiddlewareHandler = (*StaticResponse)(nil)