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
a39e71ca
Commit
a39e71ca
authored
Mar 28, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored headers middleware to return errors
parent
8f4e7f7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
11 deletions
+7
-11
middleware/headers/headers.go
middleware/headers/headers.go
+5
-5
middleware/headers/new.go
middleware/headers/new.go
+2
-6
No files found.
middleware/headers/headers.go
View file @
a39e71ca
...
...
@@ -12,13 +12,13 @@ import (
// Headers is middleware that adds headers to the responses
// for requests matching a certain path.
type
Headers
struct
{
Next
http
.
HandlerFunc
Next
middleware
.
HandlerFunc
Rules
[]
HeaderRule
}
// ServeHTTP implements the
http.Handler interface and serves the
requests,
// ServeHTTP implements the
middleware.Handler interface and serves
requests,
// adding headers to the response according to the configured rules.
func
(
h
Headers
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
h
Headers
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
for
_
,
rule
:=
range
h
.
Rules
{
if
middleware
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
rule
.
Url
)
{
for
_
,
header
:=
range
rule
.
Headers
{
...
...
@@ -26,12 +26,12 @@ func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
}
h
.
Next
(
w
,
r
)
return
h
.
Next
(
w
,
r
)
}
type
(
// HeaderRule groups a slice of HTTP headers by a URL pattern.
// TODO: use http.Header type instead?
?
// TODO: use http.Header type instead?
HeaderRule
struct
{
Url
string
Headers
[]
Header
...
...
middleware/headers/new.go
View file @
a39e71ca
package
headers
import
(
"net/http"
"github.com/mholt/caddy/middleware"
)
import
"github.com/mholt/caddy/middleware"
// New constructs and configures a new headers middleware instance.
func
New
(
c
middleware
.
Controller
)
(
middleware
.
Middleware
,
error
)
{
...
...
@@ -14,7 +10,7 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
return
nil
,
err
}
return
func
(
next
http
.
HandlerFunc
)
http
.
HandlerFunc
{
return
func
(
next
middleware
.
HandlerFunc
)
middleware
.
HandlerFunc
{
return
Headers
{
Next
:
next
,
Rules
:
rules
}
.
ServeHTTP
},
nil
}
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