mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
parent
b23e7c090a
commit
eb48e7de60
16
context.go
16
context.go
@ -338,27 +338,21 @@ func (c *echoContext) Render(code int, name string, data interface{}) (err error
|
|||||||
if err = c.echo.renderer.Render(buf, name, data, c); err != nil {
|
if err = c.echo.renderer.Render(buf, name, data, c); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, MIMETextHTMLCharsetUTF8)
|
c.response.Header().Set(HeaderContentType, MIMETextHTMLCharsetUTF8)
|
||||||
}
|
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
_, err = c.response.Write(buf.Bytes())
|
_, err = c.response.Write(buf.Bytes())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *echoContext) HTML(code int, html string) (err error) {
|
func (c *echoContext) HTML(code int, html string) (err error) {
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, MIMETextHTMLCharsetUTF8)
|
c.response.Header().Set(HeaderContentType, MIMETextHTMLCharsetUTF8)
|
||||||
}
|
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
_, err = c.response.Write([]byte(html))
|
_, err = c.response.Write([]byte(html))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *echoContext) String(code int, s string) (err error) {
|
func (c *echoContext) String(code int, s string) (err error) {
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, MIMETextPlainCharsetUTF8)
|
c.response.Header().Set(HeaderContentType, MIMETextPlainCharsetUTF8)
|
||||||
}
|
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
_, err = c.response.Write([]byte(s))
|
_, err = c.response.Write([]byte(s))
|
||||||
return
|
return
|
||||||
@ -376,9 +370,7 @@ func (c *echoContext) JSON(code int, i interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *echoContext) JSONBlob(code int, b []byte) (err error) {
|
func (c *echoContext) JSONBlob(code int, b []byte) (err error) {
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, MIMEApplicationJSONCharsetUTF8)
|
c.response.Header().Set(HeaderContentType, MIMEApplicationJSONCharsetUTF8)
|
||||||
}
|
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
_, err = c.response.Write(b)
|
_, err = c.response.Write(b)
|
||||||
return
|
return
|
||||||
@ -389,9 +381,7 @@ func (c *echoContext) JSONP(code int, callback string, i interface{}) (err error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, MIMEApplicationJavaScriptCharsetUTF8)
|
c.response.Header().Set(HeaderContentType, MIMEApplicationJavaScriptCharsetUTF8)
|
||||||
}
|
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
if _, err = c.response.Write([]byte(callback + "(")); err != nil {
|
if _, err = c.response.Write([]byte(callback + "(")); err != nil {
|
||||||
return
|
return
|
||||||
@ -415,9 +405,7 @@ func (c *echoContext) XML(code int, i interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *echoContext) XMLBlob(code int, b []byte) (err error) {
|
func (c *echoContext) XMLBlob(code int, b []byte) (err error) {
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, MIMEApplicationXMLCharsetUTF8)
|
c.response.Header().Set(HeaderContentType, MIMEApplicationXMLCharsetUTF8)
|
||||||
}
|
|
||||||
c.response.WriteHeader(code)
|
c.response.WriteHeader(code)
|
||||||
if _, err = c.response.Write([]byte(xml.Header)); err != nil {
|
if _, err = c.response.Write([]byte(xml.Header)); err != nil {
|
||||||
return
|
return
|
||||||
@ -448,9 +436,7 @@ func (c *echoContext) File(file string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *echoContext) Attachment(r io.ReadSeeker, name string) (err error) {
|
func (c *echoContext) Attachment(r io.ReadSeeker, name string) (err error) {
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
c.response.Header().Set(HeaderContentType, ContentTypeByExtension(name))
|
c.response.Header().Set(HeaderContentType, ContentTypeByExtension(name))
|
||||||
}
|
|
||||||
c.response.Header().Set(HeaderContentDisposition, "attachment; filename="+name)
|
c.response.Header().Set(HeaderContentDisposition, "attachment; filename="+name)
|
||||||
c.response.WriteHeader(http.StatusOK)
|
c.response.WriteHeader(http.StatusOK)
|
||||||
_, err = io.Copy(c.response, r)
|
_, err = io.Copy(c.response, r)
|
||||||
@ -501,9 +487,7 @@ func (c *echoContext) ServeContent(content io.ReadSeeker, name string, modtime t
|
|||||||
return c.NoContent(http.StatusNotModified)
|
return c.NoContent(http.StatusNotModified)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.response.Header().Get(HeaderContentType) == "" {
|
|
||||||
res.Header().Set(HeaderContentType, ContentTypeByExtension(name))
|
res.Header().Set(HeaderContentType, ContentTypeByExtension(name))
|
||||||
}
|
|
||||||
res.Header().Set(HeaderLastModified, modtime.UTC().Format(http.TimeFormat))
|
res.Header().Set(HeaderLastModified, modtime.UTC().Format(http.TimeFormat))
|
||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
_, err := io.Copy(res, content)
|
_, err := io.Copy(res, content)
|
||||||
|
Loading…
Reference in New Issue
Block a user