mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-24 09:05:37 +08:00
Controller/Dispenser refactoring, typo fixes
This commit is contained in:
parent
6bf36d922c
commit
4e9c432c14
|
@ -97,6 +97,7 @@ func (h ErrorHandler) errorPage(w http.ResponseWriter, code int) {
|
|||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(code)
|
||||
_, err = io.Copy(w, errorPage)
|
||||
|
||||
if err != nil {
|
||||
// Epic fail... sigh.
|
||||
h.Log.Printf("HTTP %d could not respond with %s: %v", code, pagePath, err)
|
||||
|
|
|
@ -37,10 +37,35 @@ type (
|
|||
ServeHTTP(http.ResponseWriter, *http.Request) (int, error)
|
||||
}
|
||||
|
||||
// A Control provides structured access to tokens from a configuration file
|
||||
// and also to properties of the server being configured. Middleware generators
|
||||
// use a Controller to construct their middleware instance.
|
||||
// A Controller provides access to properties of the server. Middleware
|
||||
// generators use a Controller to construct their instances.
|
||||
Controller interface {
|
||||
Dispenser
|
||||
|
||||
// Startup registers a function to execute when the server starts.
|
||||
Startup(func() error)
|
||||
|
||||
// Shutdown registers a function to execute when the server exits.
|
||||
Shutdown(func() error)
|
||||
|
||||
// Root returns the file path from which the server is serving.
|
||||
Root() string
|
||||
|
||||
// Host returns the hostname the server is bound to.
|
||||
Host() string
|
||||
|
||||
// Port returns the port that the server is listening on.
|
||||
Port() string
|
||||
|
||||
// Context returns the path scope that the Controller is in.
|
||||
// Note: This is not currently used, but may be in the future.
|
||||
Context() Path
|
||||
}
|
||||
|
||||
// A Dispenser provides structured access to tokens from a configuration
|
||||
// file. It dispenses tokens to middleware for parsing so that middleware
|
||||
// can configure themselves.
|
||||
Dispenser interface {
|
||||
// Next loads the next token. Returns true if a token
|
||||
// was loaded; false otherwise. If false, all tokens
|
||||
// have already been consumed.
|
||||
|
@ -91,24 +116,5 @@ type (
|
|||
|
||||
// Err generates a custom parse error with a message of msg.
|
||||
Err(string) error
|
||||
|
||||
// Startup registers a function to execute when the server starts.
|
||||
Startup(func() error)
|
||||
|
||||
// Shutdown registers a function to execute when the server exits.
|
||||
Shutdown(func() error)
|
||||
|
||||
// Root returns the file path from which the server is serving.
|
||||
Root() string
|
||||
|
||||
// Host returns the hostname the server is bound to.
|
||||
Host() string
|
||||
|
||||
// Port returns the port that the server is listening on.
|
||||
Port() string
|
||||
|
||||
// Context returns the path scope that the Controller is in.
|
||||
// Note: This is not currently used, but may be in the future.
|
||||
Context() Path
|
||||
}
|
||||
)
|
||||
|
|
|
@ -46,7 +46,7 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
|
|||
for _, rule := range redirects {
|
||||
if r.URL.Path == rule.From {
|
||||
http.Redirect(w, r, rule.To, rule.Code)
|
||||
break
|
||||
return 0, nil
|
||||
}
|
||||
}
|
||||
return next(w, r)
|
||||
|
|
Loading…
Reference in New Issue
Block a user