diff --git a/mango.go b/mango.go index fd9c24c..f9d4fd0 100644 --- a/mango.go +++ b/mango.go @@ -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)) } } diff --git a/static/binary_file.png b/static/binary_file.png new file mode 100644 index 0000000..e2af0dc Binary files /dev/null and b/static/binary_file.png differ diff --git a/static_test.go b/static_test.go index c631dcb..6c67a08 100644 --- a/static_test.go +++ b/static_test.go @@ -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()