Skip to content

Commit

Permalink
JMS #91: Fixed Gzip middleware to not break the Before hook
Browse files Browse the repository at this point in the history
  • Loading branch information
codegangsta committed Jan 16, 2014
1 parent e76b64f commit b58b372
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gzip/gzip.go
Expand Up @@ -27,7 +27,7 @@ var serveGzip = func(w http.ResponseWriter, r *http.Request, c martini.Context)
gz := gzip.NewWriter(w)
defer gz.Close()

gzw := gzipResponseWriter{gz, martini.NewResponseWriter(w)}
gzw := gzipResponseWriter{gz, w.(martini.ResponseWriter)}
c.MapTo(gzw, (*http.ResponseWriter)(nil))

c.Next()
Expand Down
10 changes: 10 additions & 0 deletions gzip/gzip_test.go
Expand Up @@ -11,9 +11,15 @@ import (
func Test_GzipAll(t *testing.T) {
// Set up
recorder := httptest.NewRecorder()
before := false

m := martini.New()
m.Use(All())
m.Use(func(r http.ResponseWriter) {
r.(martini.ResponseWriter).Before(func(rw martini.ResponseWriter) {
before = true
})
})

r, err := http.NewRequest("GET", "/", nil)
if err != nil {
Expand Down Expand Up @@ -47,4 +53,8 @@ func Test_GzipAll(t *testing.T) {
if !strings.EqualFold(ce, "gzip") {
t.Error(HeaderContentEncoding + " is not 'gzip'")
}

if before == false {
t.Error("Before hook was not called")
}
}

0 comments on commit b58b372

Please sign in to comment.