Переглянути джерело

Merge branch 'master' into develop

Manu Mtz.-Almeida 10 роки тому
батько
коміт
9abb909731
2 змінених файлів з 11 додано та 7 видалено
  1. 1 1
      CHANGELOG.md
  2. 10 6
      context.go

+ 1 - 1
CHANGELOG.md

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

+ 10 - 6
context.go

@@ -114,7 +114,7 @@ func (c *Context) Abort() {
 // 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).
 func (c *Context) AbortWithStatus(code int) {
-	c.Writer.WriteHeader(code)
+	c.Status(code)
 	c.Abort()
 }
 
@@ -315,6 +315,10 @@ func (c *Context) requestHeader(key string) string {
 /******** RESPONSE RENDERING ********/
 /************************************/
 
+func (c *Context) Status(code int) {
+	c.writermem.WriteHeader(code)
+}
+
 // Header is a intelligent shortcut for c.Writer.Header().Set(key, value)
 // It writes a header in the response.
 // 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) {
-	c.writermem.WriteHeader(code)
+	c.Status(code)
 	if err := r.Render(c.Writer); err != nil {
 		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.
 // It also sets the Content-Type as "application/json".
 func (c *Context) JSON(code int, obj interface{}) {
-	c.writermem.WriteHeader(code)
+	c.Status(code)
 	if err := render.WriteJSON(c.Writer, obj); err != nil {
 		c.renderError(err)
 	}
@@ -407,7 +411,7 @@ func (c *Context) XML(code int, obj interface{}) {
 
 // String writes the given string into the response body.
 func (c *Context) String(code int, format string, values ...interface{}) {
-	c.writermem.WriteHeader(code)
+	c.Status(code)
 	render.WriteString(c.Writer, format, values)
 }
 
@@ -449,9 +453,9 @@ func (c *Context) Stream(step func(w io.Writer) bool) {
 		case <-clientGone:
 			return
 		default:
-			keepopen := step(w)
+			keepOpen := step(w)
 			w.Flush()
-			if !keepopen {
+			if !keepOpen {
 				return
 			}
 		}