Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
3933cb23
Commit
3933cb23
authored
May 24, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: fix Set-Cookie date parsing
Fixes #1855 R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/4527073
parent
b3d3762b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
7 deletions
+40
-7
src/pkg/http/cookie.go
src/pkg/http/cookie.go
+26
-6
src/pkg/http/cookie_test.go
src/pkg/http/cookie_test.go
+14
-1
No files found.
src/pkg/http/cookie.go
View file @
3933cb23
...
...
@@ -81,12 +81,17 @@ func readSetCookies(h Header) []*Cookie {
if
j
:=
strings
.
Index
(
attr
,
"="
);
j
>=
0
{
attr
,
val
=
attr
[
:
j
],
attr
[
j
+
1
:
]
}
val
,
success
=
parseCookieValue
(
val
)
lowerAttr
:=
strings
.
ToLower
(
attr
)
parseCookieValueFn
:=
parseCookieValue
if
lowerAttr
==
"expires"
{
parseCookieValueFn
=
parseCookieExpiresValue
}
val
,
success
=
parseCookieValueFn
(
val
)
if
!
success
{
c
.
Unparsed
=
append
(
c
.
Unparsed
,
parts
[
i
])
continue
}
switch
strings
.
ToLower
(
attr
)
{
switch
lowerAttr
{
case
"secure"
:
c
.
Secure
=
true
continue
...
...
@@ -112,8 +117,11 @@ func readSetCookies(h Header) []*Cookie {
c
.
RawExpires
=
val
exptime
,
err
:=
time
.
Parse
(
time
.
RFC1123
,
val
)
if
err
!=
nil
{
c
.
Expires
=
time
.
Time
{}
break
exptime
,
err
=
time
.
Parse
(
"Mon, 02-Jan-2006 15:04:05 MST"
,
val
)
if
err
!=
nil
{
c
.
Expires
=
time
.
Time
{}
break
}
}
c
.
Expires
=
*
exptime
continue
...
...
@@ -272,7 +280,7 @@ func unquoteCookieValue(v string) string {
}
func
isCookieByte
(
c
byte
)
bool
{
switch
true
{
switch
{
case
c
==
0x21
,
0x23
<=
c
&&
c
<=
0x2b
,
0x2d
<=
c
&&
c
<=
0x3a
,
0x3c
<=
c
&&
c
<=
0x5b
,
0x5d
<=
c
&&
c
<=
0x7e
:
return
true
...
...
@@ -280,10 +288,22 @@ func isCookieByte(c byte) bool {
return
false
}
func
isCookieExpiresByte
(
c
byte
)
(
ok
bool
)
{
return
isCookieByte
(
c
)
||
c
==
','
||
c
==
' '
}
func
parseCookieValue
(
raw
string
)
(
string
,
bool
)
{
return
parseCookieValueUsing
(
raw
,
isCookieByte
)
}
func
parseCookieExpiresValue
(
raw
string
)
(
string
,
bool
)
{
return
parseCookieValueUsing
(
raw
,
isCookieExpiresByte
)
}
func
parseCookieValueUsing
(
raw
string
,
validByte
func
(
byte
)
bool
)
(
string
,
bool
)
{
raw
=
unquoteCookieValue
(
raw
)
for
i
:=
0
;
i
<
len
(
raw
);
i
++
{
if
!
isCookie
Byte
(
raw
[
i
])
{
if
!
valid
Byte
(
raw
[
i
])
{
return
""
,
false
}
}
...
...
src/pkg/http/cookie_test.go
View file @
3933cb23
...
...
@@ -11,9 +11,9 @@ import (
"os"
"reflect"
"testing"
"time"
)
var
writeSetCookiesTests
=
[]
struct
{
Cookies
[]
*
Cookie
Raw
string
...
...
@@ -115,6 +115,19 @@ var readSetCookiesTests = []struct {
Header
{
"Set-Cookie"
:
{
"Cookie-1=v$1"
}},
[]
*
Cookie
{
&
Cookie
{
Name
:
"Cookie-1"
,
Value
:
"v$1"
,
Raw
:
"Cookie-1=v$1"
}},
},
{
Header
{
"Set-Cookie"
:
{
"NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"
}},
[]
*
Cookie
{
&
Cookie
{
Name
:
"NID"
,
Value
:
"99=YsDT5i3E-CXax-"
,
Path
:
"/"
,
Domain
:
".google.ch"
,
HttpOnly
:
true
,
Expires
:
time
.
Time
{
Year
:
2011
,
Month
:
11
,
Day
:
23
,
Hour
:
1
,
Minute
:
5
,
Second
:
3
,
Weekday
:
3
,
ZoneOffset
:
0
,
Zone
:
"GMT"
},
RawExpires
:
"Wed, 23-Nov-2011 01:05:03 GMT"
,
Raw
:
"NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"
,
}},
},
}
func
toJSON
(
v
interface
{})
string
{
...
...
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