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
73d757e3
Commit
73d757e3
authored
Apr 05, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
context: improve the formParse
parent
deb28dd8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
3 deletions
+59
-3
input.go
context/input.go
+59
-3
No files found.
context/input.go
View file @
73d757e3
...
...
@@ -2,6 +2,7 @@ package context
import
(
"bytes"
"errors"
"io/ioutil"
"net/http"
"reflect"
...
...
@@ -92,6 +93,41 @@ func (input *BeegoInput) Is(method string) bool {
return
input
.
Method
()
==
method
}
// Is this a GET method request?
func
(
input
*
BeegoInput
)
IsGet
()
bool
{
return
input
.
Is
(
"GET"
)
}
// Is this a POST method request?
func
(
input
*
BeegoInput
)
IsPost
()
bool
{
return
input
.
Is
(
"POST"
)
}
// Is this a Head method request?
func
(
input
*
BeegoInput
)
IsHead
()
bool
{
return
input
.
Is
(
"HEAD"
)
}
// Is this a OPTIONS method request?
func
(
input
*
BeegoInput
)
IsOptions
()
bool
{
return
input
.
Is
(
"OPTIONS"
)
}
// Is this a PUT method request?
func
(
input
*
BeegoInput
)
IsPut
()
bool
{
return
input
.
Is
(
"PUT"
)
}
// Is this a DELETE method request?
func
(
input
*
BeegoInput
)
IsDelete
()
bool
{
return
input
.
Is
(
"DELETE"
)
}
// Is this a PATCH method request?
func
(
input
*
BeegoInput
)
IsPatch
()
bool
{
return
input
.
Is
(
"PATCH"
)
}
// IsAjax returns boolean of this request is generated by ajax.
func
(
input
*
BeegoInput
)
IsAjax
()
bool
{
return
input
.
Header
(
"X-Requested-With"
)
==
"XMLHttpRequest"
...
...
@@ -109,7 +145,7 @@ func (input *BeegoInput) IsWebsocket() bool {
// IsSecure returns boolean of whether file uploads in this request or not..
func
(
input
*
BeegoInput
)
IsUpload
()
bool
{
return
input
.
Request
.
MultipartForm
!=
nil
return
input
.
Header
(
"Content-Type"
)
==
"multipart/form-data"
}
// IP returns request client ip.
...
...
@@ -175,7 +211,9 @@ func (input *BeegoInput) Param(key string) string {
// Query returns input data item string by a given string.
func
(
input
*
BeegoInput
)
Query
(
key
string
)
string
{
input
.
Request
.
ParseForm
()
if
input
.
Request
.
Form
==
nil
{
input
.
Request
.
ParseForm
()
}
return
input
.
Request
.
Form
.
Get
(
key
)
}
...
...
@@ -200,7 +238,7 @@ func (input *BeegoInput) Session(key interface{}) interface{} {
}
// Body returns the raw request body data as bytes.
func
(
input
*
BeegoInput
)
Body
()
[]
byte
{
func
(
input
*
BeegoInput
)
Copy
Body
()
[]
byte
{
requestbody
,
_
:=
ioutil
.
ReadAll
(
input
.
Request
.
Body
)
input
.
Request
.
Body
.
Close
()
bf
:=
bytes
.
NewBuffer
(
requestbody
)
...
...
@@ -222,3 +260,21 @@ func (input *BeegoInput) GetData(key interface{}) interface{} {
func
(
input
*
BeegoInput
)
SetData
(
key
,
val
interface
{})
{
input
.
Data
[
key
]
=
val
}
func
(
input
*
BeegoInput
)
ParseFormOrMulitForm
(
maxMemory
int64
)
error
{
// Parse the body depending on the content type.
switch
input
.
Header
(
"Content-Type"
)
{
case
"application/x-www-form-urlencoded"
:
// Typical form.
if
err
:=
input
.
Request
.
ParseForm
();
err
!=
nil
{
return
errors
.
New
(
"Error parsing request body:"
+
err
.
Error
())
}
case
"multipart/form-data"
:
if
err
:=
input
.
Request
.
ParseMultipartForm
(
maxMemory
);
err
!=
nil
{
return
errors
.
New
(
"Error parsing request body:"
+
err
.
Error
())
}
}
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