@marcel91200 / caddy Mirror · read-only / commits / d030bfda
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

httpcaddyfile: static_response -> respond; minor cleanups

Matthew Holt committed Sep 16, 2019 at 11:04 UTC d030bfdae065c8776e8ac14c0a28f725ec05145c
5 files changed +17 -11
caddyconfig/caddyfile/parse_test.go
-2
@@ -22,8 +22,6 @@ import (
22 "testing"
23 )
24
25 -// TODO: re-enable all tests
26 -
25 func TestAllTokens(t *testing.T) {
26 input := strings.NewReader("a b c\nd e")
27 expected := []string{"a", "b", "c", "d", "e"}
caddyconfig/httpcaddyfile/builtins.go
+10
@@ -31,6 +31,7 @@ func init() {
31 RegisterDirective("root", parseRoot)
32 RegisterDirective("tls", parseTLS)
33 RegisterHandlerDirective("redir", parseRedir)
34 + RegisterHandlerDirective("respond", parseRespond)
35 }
36
37 func parseBind(h Helper) ([]ConfigValue, error) {
@@ -253,3 +254,12 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) {
254 Body: body,
255 }, nil
256 }
257 +
258 +func parseRespond(h Helper) (caddyhttp.MiddlewareHandler, error) {
259 + sr := new(caddyhttp.StaticResponse)
260 + err := sr.UnmarshalCaddyfile(h.Dispenser)
261 + if err != nil {
262 + return nil, err
263 + }
264 + return sr, nil
265 +}
caddyconfig/httpcaddyfile/directives.go
+1 -2
@@ -25,7 +25,6 @@ import (
25
26 // defaultDirectiveOrder specifies the order
27 // to apply directives in HTTP routes.
28 -// TODO: finish the ability to customize this
28 var defaultDirectiveOrder = []string{
29 "rewrite",
30 "try_files",
@@ -34,7 +33,7 @@ var defaultDirectiveOrder = []string{
33 "encode",
34 "templates",
35 "redir",
37 - "static_response", // TODO: "reply" or "respond"?
36 + "respond",
37 "reverse_proxy",
38 "php_fastcgi",
39 "file_server",
modules/caddyhttp/encode/caddyfile.go
-3
@@ -29,7 +29,6 @@ func init() {
29 httpcaddyfile.RegisterHandlerDirective("encode", parseCaddyfile)
30 }
31
32 -// TODO: This is a good example of why UnmarshalCaddyfile is still a good idea... hmm.
32 func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
33 enc := new(Encode)
34 err := enc.UnmarshalCaddyfile(h.Dispenser)
@@ -39,8 +38,6 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
38 return enc, nil
39 }
40
42 -// TODO: Keep UnmarshalCaddyfile pattern?
43 -
41 // UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
42 //
43 // encode [<matcher>] <formats...> {
modules/caddyhttp/staticresp.go
+6 -4
@@ -25,7 +25,6 @@ import (
25
26 func init() {
27 caddy.RegisterModule(StaticResponse{})
28 - // TODO: Caddyfile directive
28 }
29
30 // StaticResponse implements a simple responder for static responses.
@@ -46,7 +45,7 @@ func (StaticResponse) CaddyModule() caddy.ModuleInfo {
45
46 // UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
47 //
49 -// static_response [<matcher>] <status> {
48 +// respond [<matcher>] <status> {
49 // body <text>
50 // close
51 // }
@@ -119,5 +118,8 @@ func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Hand
118 return nil
119 }
120
122 -// Interface guard
123 -var _ MiddlewareHandler = (*StaticResponse)(nil)
121 +// Interface guards
122 +var (
123 + _ MiddlewareHandler = (*StaticResponse)(nil)
124 + _ caddyfile.Unmarshaler = (*StaticResponse)(nil)
125 +)