Browse Source

use stdlib header instead

tags/v0.9.0
jimzhan 9 years ago
parent
commit
80d0335481
2 changed files with 5 additions and 5 deletions
  1. +2
    -2
      middleware/header.go
  2. +3
    -3
      middleware/header_test.go

+ 2
- 2
middleware/header.go View File

import "net/http" import "net/http"


// Header adds the given response headers to the upcoming `http.ResponseWriter`. // Header adds the given response headers to the upcoming `http.ResponseWriter`.
func Header(values map[string]string) func(http.Handler) http.Handler {
func Header(values http.Header) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for key, value := range values { for key, value := range values {
w.Header().Set(key, value)
w.Header()[key] = value
} }
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
}) })

+ 3
- 3
middleware/header_test.go View File

) )


func TestHeader(t *testing.T) { func TestHeader(t *testing.T) {
var values = make(map[string]string)
values["X-Powered-By"] = "rex server"
var values = make(http.Header)
values.Set("X-Powered-By", "rex")


app := rex.New() app := rex.New()
app.Use(Header(values)) app.Use(Header(values))


app.ServeHTTP(response, request) app.ServeHTTP(response, request)


So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex server")
So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
}) })
} }

Loading…
Cancel
Save