Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
7bfb4126
authored
2013-07-08 23:12:31 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
support copy requestbody
1 parent
2abe584b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
2 deletions
beego.go
config.go
context.go
router.go
beego.go
View file @
7bfb412
...
...
@@ -45,6 +45,7 @@ var (
HttpServerTimeOut
int64
ErrorsShow
bool
XSRFKEY
string
CopyRequestBody
bool
)
func
init
()
{
...
...
config.go
View file @
7bfb412
...
...
@@ -186,6 +186,9 @@ func ParseConfig() (err error) {
if
errorsshow
,
err
:=
AppConfig
.
Bool
(
"errorsshow"
);
err
==
nil
{
ErrorsShow
=
errorsshow
}
if
copyrequestbody
,
err
:=
AppConfig
.
Bool
(
"copyrequestbody"
);
err
==
nil
{
CopyRequestBody
=
copyrequestbody
}
if
xsrfkey
:=
AppConfig
.
String
(
"xsrfkey"
);
xsrfkey
!=
""
{
XSRFKEY
=
xsrfkey
}
...
...
context.go
View file @
7bfb412
...
...
@@ -11,6 +11,7 @@ import (
type
Context
struct
{
ResponseWriter
http
.
ResponseWriter
Request
*
http
.
Request
RequestBody
[]
byte
Params
map
[
string
]
string
}
...
...
router.go
View file @
7bfb412
package
beego
import
(
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
...
...
@@ -258,6 +260,18 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
requestPath
:=
r
.
URL
.
Path
var
requestbody
[]
byte
if
CopyRequestBody
{
requestbody
,
_
=
ioutil
.
ReadAll
(
r
.
Body
)
r
.
Body
.
Close
()
bf
:=
bytes
.
NewBuffer
(
requestbody
)
r
.
Body
=
ioutil
.
NopCloser
(
bf
)
}
r
.
ParseMultipartForm
(
MaxMemory
)
//user defined Handler
...
...
@@ -346,7 +360,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
params
[
route
.
params
[
i
]]
=
match
}
//reassemble query params and add to RawQuery
r
.
URL
.
RawQuery
=
url
.
Values
(
values
)
.
Encode
()
+
"&"
+
r
.
URL
.
RawQuery
r
.
URL
.
RawQuery
=
url
.
Values
(
values
)
.
Encode
()
//r.URL.RawQuery = url.Values(values).Encode()
}
runrouter
=
route
...
...
@@ -370,7 +384,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
//call the controller init function
init
:=
vc
.
MethodByName
(
"Init"
)
in
:=
make
([]
reflect
.
Value
,
2
)
ct
:=
&
Context
{
ResponseWriter
:
w
,
Request
:
r
,
Params
:
params
}
ct
:=
&
Context
{
ResponseWriter
:
w
,
Request
:
r
,
Params
:
params
,
RequestBody
:
requestbody
}
in
[
0
]
=
reflect
.
ValueOf
(
ct
)
in
[
1
]
=
reflect
.
ValueOf
(
runrouter
.
controllerType
.
Name
())
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment