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
fd4630c6
Commit
fd4630c6
authored
Nov 04, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
impove the ResponseWriter. fix #1410
parent
e3120226
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
25 deletions
+6
-25
router.go
router.go
+6
-25
No files found.
router.go
View file @
fd4630c6
...
...
@@ -15,10 +15,7 @@
package
beego
import
(
"bufio"
"errors"
"fmt"
"net"
"net/http"
"os"
"path"
...
...
@@ -581,7 +578,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
var
runMethod
string
var
routerInfo
*
controllerInfo
w
:=
&
responseWriter
{
writer
:
rw
}
w
:=
&
responseWriter
{
rw
,
false
,
0
}
if
RunMode
==
"dev"
{
w
.
Header
()
.
Set
(
"Server"
,
BeegoServerName
)
...
...
@@ -856,7 +853,7 @@ Admin:
// Call WriteHeader if status code has been set changed
if
context
.
Output
.
Status
!=
0
{
w
.
writer
.
WriteHeader
(
context
.
Output
.
Status
)
w
.
WriteHeader
(
context
.
Output
.
Status
)
}
}
...
...
@@ -895,14 +892,14 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
//responseWriter is a wrapper for the http.ResponseWriter
//started set to true if response was written to then don't execute other handler
type
responseWriter
struct
{
writer
http
.
ResponseWriter
http
.
ResponseWriter
started
bool
status
int
}
// Header returns the header map that will be sent by WriteHeader.
func
(
w
*
responseWriter
)
Header
()
http
.
Header
{
return
w
.
w
riter
.
Header
()
return
w
.
ResponseW
riter
.
Header
()
}
// Write writes the data to the connection as part of an HTTP reply,
...
...
@@ -910,7 +907,7 @@ func (w *responseWriter) Header() http.Header {
// started means the response has sent out.
func
(
w
*
responseWriter
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
w
.
started
=
true
return
w
.
w
riter
.
Write
(
p
)
return
w
.
ResponseW
riter
.
Write
(
p
)
}
// WriteHeader sends an HTTP response header with status code,
...
...
@@ -918,23 +915,7 @@ func (w *responseWriter) Write(p []byte) (int, error) {
func
(
w
*
responseWriter
)
WriteHeader
(
code
int
)
{
w
.
status
=
code
w
.
started
=
true
w
.
writer
.
WriteHeader
(
code
)
}
// hijacker for http
func
(
w
*
responseWriter
)
Hijack
()
(
net
.
Conn
,
*
bufio
.
ReadWriter
,
error
)
{
hj
,
ok
:=
w
.
writer
.
(
http
.
Hijacker
)
if
!
ok
{
return
nil
,
nil
,
errors
.
New
(
"webserver doesn't support hijacking"
)
}
return
hj
.
Hijack
()
}
func
(
w
*
responseWriter
)
Flush
()
{
f
,
ok
:=
w
.
writer
.
(
http
.
Flusher
)
if
ok
{
f
.
Flush
()
}
w
.
ResponseWriter
.
WriteHeader
(
code
)
}
func
tourl
(
params
map
[
string
]
string
)
string
{
...
...
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