Merge branch 'master' into develop

This commit is contained in:
Manu Mtz.-Almeida 2016-01-26 15:55:44 +01:00
commit 9abb909731
2 changed files with 11 additions and 7 deletions

View File

@ -2,7 +2,7 @@
###Gin 1.0rc2 (...) ###Gin 1.0rc2 (...)
- [PERFORMANCE] Fast path for writting Content-Type. - [PERFORMANCE] Fast path for writing Content-Type.
- [PERFORMANCE] Much faster 404 routing - [PERFORMANCE] Much faster 404 routing
- [PERFORMANCE] Allocation optimizations - [PERFORMANCE] Allocation optimizations
- [PERFORMANCE] Faster root tree lookup - [PERFORMANCE] Faster root tree lookup

View File

@ -114,7 +114,7 @@ func (c *Context) Abort() {
// AbortWithStatus calls `Abort()` and writes the headers with the specified status code. // AbortWithStatus calls `Abort()` and writes the headers with the specified status code.
// For example, a failed attempt to authentificate a request could use: context.AbortWithStatus(401). // For example, a failed attempt to authentificate a request could use: context.AbortWithStatus(401).
func (c *Context) AbortWithStatus(code int) { func (c *Context) AbortWithStatus(code int) {
c.Writer.WriteHeader(code) c.Status(code)
c.Abort() c.Abort()
} }
@ -315,6 +315,10 @@ func (c *Context) requestHeader(key string) string {
/******** RESPONSE RENDERING ********/ /******** RESPONSE RENDERING ********/
/************************************/ /************************************/
func (c *Context) Status(code int) {
c.writermem.WriteHeader(code)
}
// Header is a intelligent shortcut for c.Writer.Header().Set(key, value) // Header is a intelligent shortcut for c.Writer.Header().Set(key, value)
// It writes a header in the response. // It writes a header in the response.
// If value == "", this method removes the header `c.Writer.Header().Del(key)` // If value == "", this method removes the header `c.Writer.Header().Del(key)`
@ -363,7 +367,7 @@ func (c *Context) GetCookie(name string) (string, error) {
} }
func (c *Context) Render(code int, r render.Render) { func (c *Context) Render(code int, r render.Render) {
c.writermem.WriteHeader(code) c.Status(code)
if err := r.Render(c.Writer); err != nil { if err := r.Render(c.Writer); err != nil {
c.renderError(err) c.renderError(err)
} }
@ -393,7 +397,7 @@ func (c *Context) IndentedJSON(code int, obj interface{}) {
// JSON serializes the given struct as JSON into the response body. // JSON serializes the given struct as JSON into the response body.
// It also sets the Content-Type as "application/json". // It also sets the Content-Type as "application/json".
func (c *Context) JSON(code int, obj interface{}) { func (c *Context) JSON(code int, obj interface{}) {
c.writermem.WriteHeader(code) c.Status(code)
if err := render.WriteJSON(c.Writer, obj); err != nil { if err := render.WriteJSON(c.Writer, obj); err != nil {
c.renderError(err) c.renderError(err)
} }
@ -407,7 +411,7 @@ func (c *Context) XML(code int, obj interface{}) {
// String writes the given string into the response body. // String writes the given string into the response body.
func (c *Context) String(code int, format string, values ...interface{}) { func (c *Context) String(code int, format string, values ...interface{}) {
c.writermem.WriteHeader(code) c.Status(code)
render.WriteString(c.Writer, format, values) render.WriteString(c.Writer, format, values)
} }
@ -449,9 +453,9 @@ func (c *Context) Stream(step func(w io.Writer) bool) {
case <-clientGone: case <-clientGone:
return return
default: default:
keepopen := step(w) keepOpen := step(w)
w.Flush() w.Flush()
if !keepopen { if !keepOpen {
return return
} }
} }