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
22671c52
authored
2014-12-17 12:06:53 +0800
by
shuo li
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Fix subdomain, add test, space and comment fix
1 parent
ab99d5f1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
5 deletions
context/input.go
context/input_test.go
context/input.go
View file @
22671c5
...
...
@@ -27,7 +27,7 @@ import (
"github.com/astaxie/beego/session"
)
// BeegoInput operates the http request header
,data ,
cookie and body.
// BeegoInput operates the http request header
, data,
cookie and body.
// it also contains router params and current session.
type
BeegoInput
struct
{
CruSession
session
.
SessionStore
...
...
@@ -153,12 +153,12 @@ func (input *BeegoInput) IsSecure() bool {
return
input
.
Scheme
()
==
"https"
}
// Is
Secure
returns boolean of this request is in webSocket.
// Is
Websocket
returns boolean of this request is in webSocket.
func
(
input
*
BeegoInput
)
IsWebsocket
()
bool
{
return
input
.
Header
(
"Upgrade"
)
==
"websocket"
}
// Is
Secure
returns boolean of whether file uploads in this request or not..
// Is
Upload
returns boolean of whether file uploads in this request or not..
func
(
input
*
BeegoInput
)
IsUpload
()
bool
{
return
strings
.
Contains
(
input
.
Header
(
"Content-Type"
),
"multipart/form-data"
)
}
...
...
@@ -189,16 +189,24 @@ func (input *BeegoInput) Proxy() []string {
return
[]
string
{}
}
// Referer returns http referer header.
func
(
input
*
BeegoInput
)
Referer
()
string
{
return
input
.
Header
(
"Referer"
)
}
// Refer returns http referer header.
func
(
input
*
BeegoInput
)
Refer
()
string
{
return
input
.
Header
(
"Referer"
)
return
input
.
Referer
(
)
}
// SubDomains returns sub domain string.
// if aa.bb.domain.com, returns aa.bb .
func
(
input
*
BeegoInput
)
SubDomains
()
string
{
parts
:=
strings
.
Split
(
input
.
Host
(),
"."
)
if
len
(
parts
)
>=
3
{
return
strings
.
Join
(
parts
[
:
len
(
parts
)
-
2
],
"."
)
}
return
""
}
// Port returns request client port.
...
...
@@ -237,6 +245,7 @@ func (input *BeegoInput) Query(key string) string {
}
// Header returns request header item string by a given string.
// if non-existed, return empty string.
func
(
input
*
BeegoInput
)
Header
(
key
string
)
string
{
return
input
.
Request
.
Header
.
Get
(
key
)
}
...
...
@@ -252,11 +261,12 @@ func (input *BeegoInput) Cookie(key string) string {
}
// Session returns current session item value by a given key.
// if non-existed, return empty string.
func
(
input
*
BeegoInput
)
Session
(
key
interface
{})
interface
{}
{
return
input
.
CruSession
.
Get
(
key
)
}
// Body returns the raw request body data as bytes.
//
Copy
Body returns the raw request body data as bytes.
func
(
input
*
BeegoInput
)
CopyBody
()
[]
byte
{
requestbody
,
_
:=
ioutil
.
ReadAll
(
input
.
Request
.
Body
)
input
.
Request
.
Body
.
Close
()
...
...
context/input_test.go
View file @
22671c5
...
...
@@ -70,3 +70,45 @@ func TestParse(t *testing.T) {
}
fmt
.
Println
(
user
)
}
func
TestSubDomain
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"http://www.example.com/?id=123&isok=true&ft=1.2&ol[0]=1&ol[1]=2&ul[]=str&ul[]=array&user.Name=astaxie"
,
nil
)
beegoInput
:=
NewInput
(
r
)
subdomain
:=
beegoInput
.
SubDomains
()
if
subdomain
!=
"www"
{
t
.
Fatal
(
"Subdomain parse error, got"
+
subdomain
)
}
r
,
_
=
http
.
NewRequest
(
"GET"
,
"http://localhost/"
,
nil
)
beegoInput
.
Request
=
r
if
beegoInput
.
SubDomains
()
!=
""
{
t
.
Fatal
(
"Subdomain parse error, should be empty, got "
+
beegoInput
.
SubDomains
())
}
r
,
_
=
http
.
NewRequest
(
"GET"
,
"http://aa.bb.example.com/"
,
nil
)
beegoInput
.
Request
=
r
if
beegoInput
.
SubDomains
()
!=
"aa.bb"
{
t
.
Fatal
(
"Subdomain parse error, got "
+
beegoInput
.
SubDomains
())
}
/* TODO Fix this
r, _ = http.NewRequest("GET", "http://127.0.0.1/", nil)
beegoInput.Request = r
if beegoInput.SubDomains() != "" {
t.Fatal("Subdomain parse error, got " + beegoInput.SubDomains())
}
*/
r
,
_
=
http
.
NewRequest
(
"GET"
,
"http://example.com/"
,
nil
)
beegoInput
.
Request
=
r
if
beegoInput
.
SubDomains
()
!=
""
{
t
.
Fatal
(
"Subdomain parse error, got "
+
beegoInput
.
SubDomains
())
}
r
,
_
=
http
.
NewRequest
(
"GET"
,
"http://aa.bb.cc.dd.example.com/"
,
nil
)
beegoInput
.
Request
=
r
if
beegoInput
.
SubDomains
()
!=
"aa.bb.cc.dd"
{
t
.
Fatal
(
"Subdomain parse error, got "
+
beegoInput
.
SubDomains
())
}
}
...
...
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