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
d2eece9a
Commit
d2eece9a
authored
May 27, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
session: #620 make the session never read empty
parent
c3a23b28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
sess_utils.go
session/sess_utils.go
+4
-2
session.go
session/session.go
+5
-3
No files found.
session/sess_utils.go
View file @
d2eece9a
...
@@ -20,6 +20,8 @@ import (
...
@@ -20,6 +20,8 @@ import (
"io"
"io"
"strconv"
"strconv"
"time"
"time"
"github.com/astaxie/beego/utils"
)
)
func
init
()
{
func
init
()
{
...
@@ -60,8 +62,8 @@ func DecodeGob(encoded []byte) (map[interface{}]interface{}, error) {
...
@@ -60,8 +62,8 @@ func DecodeGob(encoded []byte) (map[interface{}]interface{}, error) {
// generateRandomKey creates a random key with the given strength.
// generateRandomKey creates a random key with the given strength.
func
generateRandomKey
(
strength
int
)
[]
byte
{
func
generateRandomKey
(
strength
int
)
[]
byte
{
k
:=
make
([]
byte
,
strength
)
k
:=
make
([]
byte
,
strength
)
if
_
,
err
:=
io
.
ReadFull
(
rand
.
Reader
,
k
);
err
!=
nil
{
if
n
,
err
:=
io
.
ReadFull
(
rand
.
Reader
,
k
);
n
!=
strength
||
err
!=
nil
{
return
nil
return
utils
.
RandomCreateBytes
(
strength
)
}
}
return
k
return
k
}
}
...
...
session/session.go
View file @
d2eece9a
...
@@ -18,6 +18,8 @@ import (
...
@@ -18,6 +18,8 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"time"
"time"
"github.com/astaxie/beego/utils"
)
)
// SessionStore contains all data for one session process with specific id.
// SessionStore contains all data for one session process with specific id.
...
@@ -237,9 +239,9 @@ func (manager *Manager) SetSecure(secure bool) {
...
@@ -237,9 +239,9 @@ func (manager *Manager) SetSecure(secure bool) {
// generate session id with rand string, unix nano time, remote addr by hash function.
// generate session id with rand string, unix nano time, remote addr by hash function.
func
(
manager
*
Manager
)
sessionId
(
r
*
http
.
Request
)
(
sid
string
)
{
func
(
manager
*
Manager
)
sessionId
(
r
*
http
.
Request
)
(
sid
string
)
{
bs
:=
make
([]
byte
,
24
)
bs
:=
make
([]
byte
,
32
)
if
_
,
err
:=
io
.
ReadFull
(
rand
.
Reader
,
bs
);
err
!=
nil
{
if
n
,
err
:=
io
.
ReadFull
(
rand
.
Reader
,
bs
);
n
!=
32
||
err
!=
nil
{
return
""
bs
=
utils
.
RandomCreateBytes
(
32
)
}
}
sig
:=
fmt
.
Sprintf
(
"%s%d%s"
,
r
.
RemoteAddr
,
time
.
Now
()
.
UnixNano
(),
bs
)
sig
:=
fmt
.
Sprintf
(
"%s%d%s"
,
r
.
RemoteAddr
,
time
.
Now
()
.
UnixNano
(),
bs
)
if
manager
.
config
.
SessionIDHashFunc
==
"md5"
{
if
manager
.
config
.
SessionIDHashFunc
==
"md5"
{
...
...
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