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
9a2696d2
Commit
9a2696d2
authored
Mar 09, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accept asta's idea see the talk
https://github.com/astaxie/beego/pull/1719
parent
b30ce768
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
10 deletions
+5
-10
context.go
context/context.go
+4
-9
controller.go
controller.go
+1
-1
No files found.
context/context.go
View file @
9a2696d2
...
...
@@ -175,16 +175,14 @@ func (ctx *Context) CheckXSRFCookie() bool {
//started set to true if response was written to then don't execute other handler
type
Response
struct
{
http
.
ResponseWriter
Started
bool
Status
int
wroteHeader
bool
Started
bool
Status
int
}
func
(
r
*
Response
)
reset
(
rw
http
.
ResponseWriter
)
{
r
.
ResponseWriter
=
rw
r
.
Status
=
0
r
.
Started
=
false
r
.
wroteHeader
=
false
}
// Write writes the data to the connection as part of an HTTP reply,
...
...
@@ -192,11 +190,6 @@ func (r *Response) reset(rw http.ResponseWriter) {
// started means the response has sent out.
func
(
w
*
Response
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
w
.
Started
=
true
if
!
w
.
wroteHeader
{
w
.
ResponseWriter
.
WriteHeader
(
w
.
Status
)
//prevent multiple response.WriteHeader calls
w
.
wroteHeader
=
true
}
return
w
.
ResponseWriter
.
Write
(
p
)
}
...
...
@@ -204,10 +197,12 @@ func (w *Response) Write(p []byte) (int, error) {
// and sets `started` to true.
func
(
w
*
Response
)
WriteHeader
(
code
int
)
{
if
w
.
Status
>
0
{
//prevent multiple response.WriteHeader calls
return
}
w
.
Status
=
code
w
.
Started
=
true
w
.
ResponseWriter
.
WriteHeader
(
w
.
Status
)
}
// Hijack hijacker for http
...
...
controller.go
View file @
9a2696d2
...
...
@@ -286,7 +286,7 @@ func (c *Controller) Abort(code string) {
// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
func
(
c
*
Controller
)
CustomAbort
(
status
int
,
body
string
)
{
c
.
Ctx
.
ResponseWriter
.
WriteHeader
(
status
)
c
.
Ctx
.
Output
.
Status
=
status
// first panic from ErrorMaps, is is user defined error functions.
if
_
,
ok
:=
ErrorMaps
[
body
];
ok
{
panic
(
body
)
...
...
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