Permalink
Browse files

Fixing binary file transmission. Resolves #15

  • Loading branch information...
paulbellamy committed Aug 27, 2011
1 parent 07c74e6 commit ea791a1fe561e34a38c36b052ebe981b5c37fe91
Showing with 31 additions and 1 deletion.
  1. +1 −1 mango.go
  2. BIN static/binary_file.png
  3. +30 −0 static_test.go
View
@@ -133,7 +133,7 @@ func (this *Stack) HandlerFunc(app App) http.HandlerFunc {
}
}
w.WriteHeader(int(status))
- fmt.Fprintf(w, string(body))
+ w.Write([]byte(body))
}
}
View
Binary file not shown.
View
@@ -1,7 +1,9 @@
package mango
import (
+ "bytes"
"http"
+ "io/ioutil"
"testing"
"runtime"
)
@@ -68,6 +70,34 @@ func TestStaticFail(t *testing.T) {
}
}
+func TestStaticBinaryFile(t *testing.T) {
+ // Compile the stack
+ staticStack := new(Stack)
+ staticStack.Middleware(Static("./static"))
+ staticApp := staticStack.Compile(staticTestServer)
+
+ // Request against it
+ request, err := http.NewRequest("GET", "http://localhost:3000/binary_file.png", nil)
+ status, _, body := staticApp(Env{"mango.request": &Request{request}})
+
+ if err != nil {
+ t.Error(err)
+ }
+
+ if status != 200 {
+ t.Error("Expected status to equal 200, got:", status)
+ }
+
+ expected, err := ioutil.ReadFile("./static/binary_file.png")
+ if err != nil {
+ t.Error(err)
+ }
+
+ if bytes.Compare([]byte(body), []byte(expected)) != 0 {
+ t.Error("Expected body to equal ./static/binary_file.png")
+ }
+}
+
func BenchmarkStatic(b *testing.B) {
b.StopTimer()

0 comments on commit ea791a1

Please sign in to comment.