Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
4e9c432c
Commit
4e9c432c
authored
Mar 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Controller/Dispenser refactoring, typo fixes
parent
6bf36d92
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
23 deletions
+30
-23
middleware/errors/errors.go
middleware/errors/errors.go
+1
-0
middleware/middleware.go
middleware/middleware.go
+28
-22
middleware/redirect/redirect.go
middleware/redirect/redirect.go
+1
-1
No files found.
middleware/errors/errors.go
View file @
4e9c432c
...
...
@@ -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
)
...
...
middleware/middleware.go
View file @
4e9c432c
...
...
@@ -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
}
)
middleware/redirect/redirect.go
View file @
4e9c432c
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment