Skip to content

Commit 09cfc2a

Browse files
committed
Merge branch 'release/0.2.12'
2 parents 6e5936b + 44ed108 commit 09cfc2a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

control.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package router
66

77
import (
8+
"compress/gzip"
89
"encoding/json"
910
"net/http"
1011
"time"
@@ -33,6 +34,9 @@ type Control struct {
3334
// CompactJSON propery defines JSON output format (default is not compact)
3435
compactJSON bool
3536

37+
// gzip propery defines compressed output
38+
gzip bool
39+
3640
// Params is set of parameters
3741
Params []Param
3842

@@ -83,6 +87,11 @@ func (c *Control) CompactJSON(mode bool) {
8387
c.compactJSON = mode
8488
}
8589

90+
// UseGZIP defines compressed output
91+
func (c *Control) UseGZIP(mode bool) {
92+
c.gzip = mode
93+
}
94+
8695
// UseTimer allow caalculate elapsed time of request handling
8796
func (c *Control) UseTimer() {
8897
c.timer = time.Now()
@@ -111,8 +120,14 @@ func (c *Control) Body(data interface{}) {
111120
}
112121
c.Writer.Header().Add("Content-type", MIMEJSON)
113122
}
114-
if c.code > 0 {
123+
if c.gzip {
124+
c.Writer.Header().Add("Content-Encoding", "gzip")
125+
c.Writer.WriteHeader(c.code)
126+
gz := gzip.NewWriter(c.Writer)
127+
gz.Write(content)
128+
gz.Close()
129+
} else {
115130
c.Writer.WriteHeader(c.code)
131+
c.Writer.Write(content)
116132
}
117-
c.Writer.Write(content)
118133
}

router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
/*
6-
Package router 0.2.11 provides fast HTTP request router.
6+
Package router 0.2.12 provides fast HTTP request router.
77
88
The router matches incoming requests by the request method and the path.
99
If a handle is registered for this path and method, the router delegates the

0 commit comments

Comments
 (0)