Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing binary file transmission. Resolves #15

  • Loading branch information...
commit ea791a1fe561e34a38c36b052ebe981b5c37fe91 1 parent 07c74e6
@paulbellamy authored
View
2  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))
}
}
View
BIN  static/binary_file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
30 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()
Please sign in to comment.
Something went wrong with that request. Please try again.