Commit 4e9c432c authored by Matthew Holt's avatar Matthew Holt

Controller/Dispenser refactoring, typo fixes

parent 6bf36d92
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment