Skip to content

Commit

Permalink
Fixing binary file transmission. Resolves #15
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Aug 27, 2011
1 parent 07c74e6 commit ea791a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mango.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Binary file added static/binary_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions static_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mango

import (
"bytes"
"http"
"io/ioutil"
"testing"
"runtime"
)
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit ea791a1

Please sign in to comment.