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
ad654793
Commit
ad654793
authored
Aug 28, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the http: multiple response.WriteHeader calls
parent
306effa3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
11 deletions
+8
-11
apiauth.go
plugins/apiauth/apiauth.go
+7
-7
cors.go
plugins/cors/cors.go
+1
-4
No files found.
plugins/apiauth/apiauth.go
View file @
ad654793
...
...
@@ -83,41 +83,41 @@ func APIBaiscAuth(appid, appkey string) beego.FilterFunc {
func
APIAuthWithFunc
(
f
AppIdToAppSecret
,
timeout
int
)
beego
.
FilterFunc
{
return
func
(
ctx
*
context
.
Context
)
{
if
ctx
.
Input
.
Query
(
"appid"
)
==
""
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"miss query param: appid"
)
return
}
appsecret
:=
f
(
ctx
.
Input
.
Query
(
"appid"
))
if
appsecret
==
""
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"not exist this appid"
)
return
}
if
ctx
.
Input
.
Query
(
"signature"
)
==
""
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"miss query param: signature"
)
return
}
if
ctx
.
Input
.
Query
(
"timestamp"
)
==
""
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"miss query param: timestamp"
)
return
}
u
,
err
:=
time
.
Parse
(
"2006-01-02 15:04:05"
,
ctx
.
Input
.
Query
(
"timestamp"
))
if
err
!=
nil
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"timestamp format is error, should 2006-01-02 15:04:05"
)
return
}
t
:=
time
.
Now
()
if
t
.
Sub
(
u
)
.
Seconds
()
>
float64
(
timeout
)
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"timeout! the request time is long ago, please try again"
)
return
}
if
ctx
.
Input
.
Query
(
"signature"
)
!=
Signature
(
appsecret
,
ctx
.
Input
.
Method
(),
ctx
.
Request
.
Form
,
ctx
.
Input
.
Uri
())
{
ctx
.
Output
.
SetStatus
(
403
)
ctx
.
ResponseWriter
.
WriteHeader
(
403
)
ctx
.
WriteString
(
"auth failed"
)
}
}
...
...
plugins/cors/cors.go
View file @
ad654793
...
...
@@ -24,7 +24,7 @@
// // - PUT and PATCH methods
// // - Origin header
// // - Credentials share
// beego.InsertFilter("*", beego.BeforeRouter,cors.Allow(&cors.Options{
// beego.InsertFilter("*", beego.BeforeRouter,
cors.Allow(&cors.Options{
// AllowOrigins: []string{"https://*.foo.com"},
// AllowMethods: []string{"PUT", "PATCH"},
// AllowHeaders: []string{"Origin"},
...
...
@@ -36,7 +36,6 @@
package
cors
import
(
"net/http"
"regexp"
"strconv"
"strings"
...
...
@@ -216,8 +215,6 @@ func Allow(opts *Options) beego.FilterFunc {
for
key
,
value
:=
range
headers
{
ctx
.
Output
.
Header
(
key
,
value
)
}
ctx
.
Output
.
SetStatus
(
http
.
StatusOK
)
ctx
.
WriteString
(
""
)
return
}
headers
=
opts
.
Header
(
origin
)
...
...
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