mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-28 06:33:47 +03:00
httpcaddyfile: static_response -> respond; minor cleanups
This commit is contained in:
parent
db4c73dd58
commit
d030bfdae0
5 changed files with 17 additions and 11 deletions
|
@ -22,8 +22,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: re-enable all tests
|
|
||||||
|
|
||||||
func TestAllTokens(t *testing.T) {
|
func TestAllTokens(t *testing.T) {
|
||||||
input := strings.NewReader("a b c\nd e")
|
input := strings.NewReader("a b c\nd e")
|
||||||
expected := []string{"a", "b", "c", "d", "e"}
|
expected := []string{"a", "b", "c", "d", "e"}
|
||||||
|
|
|
@ -31,6 +31,7 @@ func init() {
|
||||||
RegisterDirective("root", parseRoot)
|
RegisterDirective("root", parseRoot)
|
||||||
RegisterDirective("tls", parseTLS)
|
RegisterDirective("tls", parseTLS)
|
||||||
RegisterHandlerDirective("redir", parseRedir)
|
RegisterHandlerDirective("redir", parseRedir)
|
||||||
|
RegisterHandlerDirective("respond", parseRespond)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseBind(h Helper) ([]ConfigValue, error) {
|
func parseBind(h Helper) ([]ConfigValue, error) {
|
||||||
|
@ -253,3 +254,12 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||||
Body: body,
|
Body: body,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseRespond(h Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||||
|
sr := new(caddyhttp.StaticResponse)
|
||||||
|
err := sr.UnmarshalCaddyfile(h.Dispenser)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return sr, nil
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
// defaultDirectiveOrder specifies the order
|
// defaultDirectiveOrder specifies the order
|
||||||
// to apply directives in HTTP routes.
|
// to apply directives in HTTP routes.
|
||||||
// TODO: finish the ability to customize this
|
|
||||||
var defaultDirectiveOrder = []string{
|
var defaultDirectiveOrder = []string{
|
||||||
"rewrite",
|
"rewrite",
|
||||||
"try_files",
|
"try_files",
|
||||||
|
@ -34,7 +33,7 @@ var defaultDirectiveOrder = []string{
|
||||||
"encode",
|
"encode",
|
||||||
"templates",
|
"templates",
|
||||||
"redir",
|
"redir",
|
||||||
"static_response", // TODO: "reply" or "respond"?
|
"respond",
|
||||||
"reverse_proxy",
|
"reverse_proxy",
|
||||||
"php_fastcgi",
|
"php_fastcgi",
|
||||||
"file_server",
|
"file_server",
|
||||||
|
|
|
@ -29,7 +29,6 @@ func init() {
|
||||||
httpcaddyfile.RegisterHandlerDirective("encode", parseCaddyfile)
|
httpcaddyfile.RegisterHandlerDirective("encode", parseCaddyfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is a good example of why UnmarshalCaddyfile is still a good idea... hmm.
|
|
||||||
func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
|
func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
|
||||||
enc := new(Encode)
|
enc := new(Encode)
|
||||||
err := enc.UnmarshalCaddyfile(h.Dispenser)
|
err := enc.UnmarshalCaddyfile(h.Dispenser)
|
||||||
|
@ -39,8 +38,6 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
|
||||||
return enc, nil
|
return enc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Keep UnmarshalCaddyfile pattern?
|
|
||||||
|
|
||||||
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
||||||
//
|
//
|
||||||
// encode [<matcher>] <formats...> {
|
// encode [<matcher>] <formats...> {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy.RegisterModule(StaticResponse{})
|
caddy.RegisterModule(StaticResponse{})
|
||||||
// TODO: Caddyfile directive
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StaticResponse implements a simple responder for static responses.
|
// StaticResponse implements a simple responder for static responses.
|
||||||
|
@ -46,7 +45,7 @@ func (StaticResponse) CaddyModule() caddy.ModuleInfo {
|
||||||
|
|
||||||
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
||||||
//
|
//
|
||||||
// static_response [<matcher>] <status> {
|
// respond [<matcher>] <status> {
|
||||||
// body <text>
|
// body <text>
|
||||||
// close
|
// close
|
||||||
// }
|
// }
|
||||||
|
@ -119,5 +118,8 @@ func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, _ Hand
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface guard
|
// Interface guards
|
||||||
var _ MiddlewareHandler = (*StaticResponse)(nil)
|
var (
|
||||||
|
_ MiddlewareHandler = (*StaticResponse)(nil)
|
||||||
|
_ caddyfile.Unmarshaler = (*StaticResponse)(nil)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue