Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
140b513c
Commit
140b513c
authored
Apr 18, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support gzip #37
parent
a3f8fd6a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
3 deletions
+42
-3
beego.go
beego.go
+7
-0
controller.go
controller.go
+35
-3
No files found.
beego.go
View file @
140b513c
...
@@ -37,6 +37,7 @@ var (
...
@@ -37,6 +37,7 @@ var (
SessionSavePath
string
// session savepath if use mysql/redis/file this set to the connectinfo
SessionSavePath
string
// session savepath if use mysql/redis/file this set to the connectinfo
UseFcgi
bool
UseFcgi
bool
MaxMemory
int64
MaxMemory
int64
EnableGzip
bool
// enable gzip
GlobalSessions
*
session
.
Manager
//GlobalSessions
GlobalSessions
*
session
.
Manager
//GlobalSessions
)
)
...
@@ -66,6 +67,7 @@ func init() {
...
@@ -66,6 +67,7 @@ func init() {
SessionSavePath
=
""
SessionSavePath
=
""
UseFcgi
=
false
UseFcgi
=
false
MaxMemory
=
1
<<
26
//64MB
MaxMemory
=
1
<<
26
//64MB
EnableGzip
=
false
}
else
{
}
else
{
HttpAddr
=
AppConfig
.
String
(
"httpaddr"
)
HttpAddr
=
AppConfig
.
String
(
"httpaddr"
)
if
v
,
err
:=
AppConfig
.
Int
(
"httpport"
);
err
!=
nil
{
if
v
,
err
:=
AppConfig
.
Int
(
"httpport"
);
err
!=
nil
{
...
@@ -135,6 +137,11 @@ func init() {
...
@@ -135,6 +137,11 @@ func init() {
}
else
{
}
else
{
UseFcgi
=
ar
UseFcgi
=
ar
}
}
if
ar
,
err
:=
AppConfig
.
Bool
(
"enablegzip"
);
err
!=
nil
{
EnableGzip
=
false
}
else
{
EnableGzip
=
ar
}
}
}
StaticDir
[
"/static"
]
=
"static"
StaticDir
[
"/static"
]
=
"static"
...
...
controller.go
View file @
140b513c
...
@@ -2,6 +2,8 @@ package beego
...
@@ -2,6 +2,8 @@ package beego
import
(
import
(
"bytes"
"bytes"
"compress/gzip"
"compress/zlib"
"encoding/json"
"encoding/json"
"encoding/xml"
"encoding/xml"
"github.com/astaxie/beego/session"
"github.com/astaxie/beego/session"
...
@@ -91,9 +93,39 @@ func (c *Controller) Render() error {
...
@@ -91,9 +93,39 @@ func (c *Controller) Render() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
else
{
}
else
{
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
rb
)),
true
)
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
c
.
Ctx
.
ContentType
(
"text/html"
)
output_writer
:=
c
.
Ctx
.
ResponseWriter
.
(
io
.
Writer
)
c
.
Ctx
.
ResponseWriter
.
Write
(
rb
)
if
EnableGzip
==
true
&&
c
.
Ctx
.
Request
.
Header
.
Get
(
"Accept-Encoding"
)
!=
""
{
splitted
:=
strings
.
SplitN
(
c
.
Ctx
.
Request
.
Header
.
Get
(
"Accept-Encoding"
),
","
,
-
1
)
encodings
:=
make
([]
string
,
len
(
splitted
))
for
i
,
val
:=
range
splitted
{
encodings
[
i
]
=
strings
.
TrimSpace
(
val
)
}
for
_
,
val
:=
range
encodings
{
if
val
==
"gzip"
{
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Encoding"
,
"gzip"
)
output_writer
,
_
=
gzip
.
NewWriterLevel
(
c
.
Ctx
.
ResponseWriter
,
gzip
.
BestSpeed
)
break
}
else
if
val
==
"deflate"
{
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Encoding"
,
"deflate"
)
output_writer
,
_
=
zlib
.
NewWriterLevel
(
c
.
Ctx
.
ResponseWriter
,
zlib
.
BestSpeed
)
break
}
}
}
else
{
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
rb
)),
true
)
}
output_writer
.
Write
(
rb
)
switch
output_writer
.
(
type
)
{
case
*
gzip
.
Writer
:
output_writer
.
(
*
gzip
.
Writer
)
.
Close
()
case
*
zlib
.
Writer
:
output_writer
.
(
*
zlib
.
Writer
)
.
Close
()
case
io
.
WriteCloser
:
output_writer
.
(
io
.
WriteCloser
)
.
Close
()
}
return
nil
return
nil
}
}
return
nil
return
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment