Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
a611480b
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a611480b
编写于
8月 05, 2013
作者:
A
astaxie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #121
上级
fd3c8834
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
40 deletion
+40
-40
controller.go
controller.go
+40
-40
未找到文件。
controller.go
浏览文件 @
a611480b
...
...
@@ -2,8 +2,8 @@ package beego
import
(
"bytes"
"compress/flate"
"compress/gzip"
"compress/zlib"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
...
...
@@ -109,39 +109,7 @@ func (c *Controller) Render() error {
return
err
}
else
{
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
output_writer
:=
c
.
Ctx
.
ResponseWriter
.
(
io
.
Writer
)
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
c
.
writeToWriter
(
rb
)
}
return
nil
}
...
...
@@ -203,6 +171,41 @@ func (c *Controller) RenderBytes() ([]byte, error) {
return
[]
byte
{},
nil
}
func
(
c
*
Controller
)
writeToWriter
(
rb
[]
byte
)
{
output_writer
:=
c
.
Ctx
.
ResponseWriter
.
(
io
.
Writer
)
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
,
_
=
flate
.
NewWriter
(
c
.
Ctx
.
ResponseWriter
,
flate
.
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
*
flate
.
Writer
:
output_writer
.
(
*
flate
.
Writer
)
.
Close
()
case
io
.
WriteCloser
:
output_writer
.
(
io
.
WriteCloser
)
.
Close
()
}
}
func
(
c
*
Controller
)
Redirect
(
url
string
,
code
int
)
{
c
.
Ctx
.
Redirect
(
code
,
url
)
}
...
...
@@ -217,9 +220,8 @@ func (c *Controller) ServeJson() {
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
content
)),
true
)
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"application/json;charset=UTF-8"
)
c
.
Ctx
.
ResponseWriter
.
Write
(
content
)
c
.
writeToWriter
(
content
)
}
func
(
c
*
Controller
)
ServeJsonp
()
{
...
...
@@ -237,9 +239,8 @@ func (c *Controller) ServeJsonp() {
callback_content
.
WriteString
(
"("
)
callback_content
.
Write
(
content
)
callback_content
.
WriteString
(
");
\r\n
"
)
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
callback_content
.
Len
()),
true
)
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"application/json;charset=UTF-8"
)
c
.
Ctx
.
ResponseWriter
.
Write
(
callback_content
.
Bytes
())
c
.
writeToWriter
(
callback_content
.
Bytes
())
}
func
(
c
*
Controller
)
ServeXml
()
{
...
...
@@ -248,9 +249,8 @@ func (c *Controller) ServeXml() {
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
content
)),
true
)
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"application/xml;charset=UTF-8"
)
c
.
Ctx
.
ResponseWriter
.
Write
(
content
)
c
.
writeToWriter
(
content
)
}
func
(
c
*
Controller
)
Input
()
url
.
Values
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录