1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00

Context.File signature changed

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-10-13 07:09:53 -07:00
parent 8f5cb6428b
commit 850bc503b0
3 changed files with 5 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import (
"net/url"
"bytes"
"golang.org/x/net/websocket"
)
@ -196,7 +197,7 @@ func (c *Context) XML(code int, i interface{}) (err error) {
// File sends a response with the content of the file. If `attachment` is set
// to true, the client is prompted to save the file with provided `name`,
// name can be empty, in that case name of the file is used.
func (c *Context) File(name, path string, attachment bool) (err error) {
func (c *Context) File(path, name string, attachment bool) (err error) {
dir, file := spath.Split(path)
if attachment {
c.response.Header().Set(ContentDisposition, "attachment; filename="+name)

View File

@ -141,7 +141,7 @@ func TestContext(t *testing.T) {
// File
rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New())
err = c.File("", "test/fixture/walle.png", false)
err = c.File("test/fixture/walle.png", "", false)
if assert.NoError(t, err) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, 219885, rec.Body.Len())
@ -150,7 +150,7 @@ func TestContext(t *testing.T) {
// File as attachment
rec = httptest.NewRecorder()
c = NewContext(req, NewResponse(rec), New())
err = c.File("WALLE.PNG", "test/fixture/walle.png", true)
err = c.File("test/fixture/walle.png", "WALLE.PNG", true)
if assert.NoError(t, err) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, rec.Header().Get(ContentDisposition), "attachment; filename=WALLE.PNG")

View File

@ -102,7 +102,7 @@ Sends a text/plain HTTP response with status code.
### File
```go
Context.File(name, path string, attachment bool) error
Context.File(path, name string, attachment bool) error
```
File sends a response with the content of the file. If `attachment` is set