summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/labstack/echo/context.go')
-rw-r--r--vendor/github.com/labstack/echo/context.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/vendor/github.com/labstack/echo/context.go b/vendor/github.com/labstack/echo/context.go
index 39801f00..cf780c51 100644
--- a/vendor/github.com/labstack/echo/context.go
+++ b/vendor/github.com/labstack/echo/context.go
@@ -206,6 +206,13 @@ const (
indexPage = "index.html"
)
+func (c *context) writeContentType(value string) {
+ header := c.Response().Header()
+ if header.Get(HeaderContentType) == "" {
+ header.Set(HeaderContentType, value)
+ }
+}
+
func (c *context) Request() *http.Request {
return c.request
}
@@ -430,7 +437,7 @@ func (c *context) JSONP(code int, callback string, i interface{}) (err error) {
}
func (c *context) JSONPBlob(code int, callback string, b []byte) (err error) {
- c.response.Header().Set(HeaderContentType, MIMEApplicationJavaScriptCharsetUTF8)
+ c.writeContentType(MIMEApplicationJavaScriptCharsetUTF8)
c.response.WriteHeader(code)
if _, err = c.response.Write([]byte(callback + "(")); err != nil {
return
@@ -463,7 +470,7 @@ func (c *context) XMLPretty(code int, i interface{}, indent string) (err error)
}
func (c *context) XMLBlob(code int, b []byte) (err error) {
- c.response.Header().Set(HeaderContentType, MIMEApplicationXMLCharsetUTF8)
+ c.writeContentType(MIMEApplicationXMLCharsetUTF8)
c.response.WriteHeader(code)
if _, err = c.response.Write([]byte(xml.Header)); err != nil {
return
@@ -473,14 +480,14 @@ func (c *context) XMLBlob(code int, b []byte) (err error) {
}
func (c *context) Blob(code int, contentType string, b []byte) (err error) {
- c.response.Header().Set(HeaderContentType, contentType)
+ c.writeContentType(contentType)
c.response.WriteHeader(code)
_, err = c.response.Write(b)
return
}
func (c *context) Stream(code int, contentType string, r io.Reader) (err error) {
- c.response.Header().Set(HeaderContentType, contentType)
+ c.writeContentType(contentType)
c.response.WriteHeader(code)
_, err = io.Copy(c.response, r)
return
@@ -509,18 +516,17 @@ func (c *context) File(file string) (err error) {
return
}
-func (c *context) Attachment(file, name string) (err error) {
+func (c *context) Attachment(file, name string) error {
return c.contentDisposition(file, name, "attachment")
}
-func (c *context) Inline(file, name string) (err error) {
+func (c *context) Inline(file, name string) error {
return c.contentDisposition(file, name, "inline")
}
-func (c *context) contentDisposition(file, name, dispositionType string) (err error) {
+func (c *context) contentDisposition(file, name, dispositionType string) error {
c.response.Header().Set(HeaderContentDisposition, fmt.Sprintf("%s; filename=%q", dispositionType, name))
- c.File(file)
- return
+ return c.File(file)
}
func (c *context) NoContent(code int) error {