Browse Source
Merge pull request #81 from mutantmonkey/addheaders
Merge pull request #81 from mutantmonkey/addheaders
Add ability to set arbitrary headerspull/83/head v1.1.11
Andrei Marcu
9 years ago
3 changed files with 61 additions and 0 deletions
-
27headers.go
-
16server.go
-
18server_test.go
@ -0,0 +1,27 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"net/http" |
|||
"strings" |
|||
) |
|||
|
|||
type addheaders struct { |
|||
h http.Handler |
|||
headers []string |
|||
} |
|||
|
|||
func (a addheaders) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|||
for _, header := range a.headers { |
|||
headerSplit := strings.SplitN(header, ": ", 2) |
|||
w.Header().Add(headerSplit[0], headerSplit[1]) |
|||
} |
|||
|
|||
a.h.ServeHTTP(w, r) |
|||
} |
|||
|
|||
func AddHeaders(headers []string) func(http.Handler) http.Handler { |
|||
fn := func(h http.Handler) http.Handler { |
|||
return addheaders{h, headers} |
|||
} |
|||
return fn |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue