Skip to content

Commit

Permalink
Merge branch 'release/0.2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Jun 15, 2015
2 parents 6e5936b + 44ed108 commit 09cfc2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package router

import (
"compress/gzip"
"encoding/json"
"net/http"
"time"
Expand Down Expand Up @@ -33,6 +34,9 @@ type Control struct {
// CompactJSON propery defines JSON output format (default is not compact)
compactJSON bool

// gzip propery defines compressed output
gzip bool

// Params is set of parameters
Params []Param

Expand Down Expand Up @@ -83,6 +87,11 @@ func (c *Control) CompactJSON(mode bool) {
c.compactJSON = mode
}

// UseGZIP defines compressed output
func (c *Control) UseGZIP(mode bool) {
c.gzip = mode
}

// UseTimer allow caalculate elapsed time of request handling
func (c *Control) UseTimer() {
c.timer = time.Now()
Expand Down Expand Up @@ -111,8 +120,14 @@ func (c *Control) Body(data interface{}) {
}
c.Writer.Header().Add("Content-type", MIMEJSON)
}
if c.code > 0 {
if c.gzip {
c.Writer.Header().Add("Content-Encoding", "gzip")
c.Writer.WriteHeader(c.code)
gz := gzip.NewWriter(c.Writer)
gz.Write(content)
gz.Close()
} else {
c.Writer.WriteHeader(c.code)
c.Writer.Write(content)
}
c.Writer.Write(content)
}
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

/*
Package router 0.2.11 provides fast HTTP request router.
Package router 0.2.12 provides fast HTTP request router.
The router matches incoming requests by the request method and the path.
If a handle is registered for this path and method, the router delegates the
Expand Down

0 comments on commit 09cfc2a

Please sign in to comment.