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
d0283ab6
Commit
d0283ab6
authored
Dec 19, 2012
by
Joakim Sernbrant
Committed by
Brad Fitzpatrick
Dec 19, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/http: only call client SetCookie when needed
R=golang-dev, bradfitz CC=golang-dev
https://golang.org/cl/6968049
parent
ff5d47eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
src/pkg/net/http/client.go
src/pkg/net/http/client.go
+3
-1
src/pkg/net/http/client_test.go
src/pkg/net/http/client_test.go
+8
-0
No files found.
src/pkg/net/http/client.go
View file @
d0283ab6
...
...
@@ -98,7 +98,9 @@ func (c *Client) send(req *Request) (*Response, error) {
return
nil
,
err
}
if
c
.
Jar
!=
nil
{
c
.
Jar
.
SetCookies
(
req
.
URL
,
resp
.
Cookies
())
if
rc
:=
resp
.
Cookies
();
len
(
rc
)
>
0
{
c
.
Jar
.
SetCookies
(
req
.
URL
,
rc
)
}
}
return
resp
,
err
}
...
...
src/pkg/net/http/client_test.go
View file @
d0283ab6
...
...
@@ -418,6 +418,9 @@ func matchReturnedCookies(t *testing.T, expected, given []*Cookie) {
func
TestJarCalls
(
t
*
testing
.
T
)
{
ts
:=
httptest
.
NewServer
(
HandlerFunc
(
func
(
w
ResponseWriter
,
r
*
Request
)
{
pathSuffix
:=
r
.
RequestURI
[
1
:
]
if
r
.
RequestURI
==
"/nosetcookie"
{
return
// dont set cookies for this path
}
SetCookie
(
w
,
&
Cookie
{
Name
:
"name"
+
pathSuffix
,
Value
:
"val"
+
pathSuffix
})
if
r
.
RequestURI
==
"/"
{
Redirect
(
w
,
r
,
"http://secondhost.fake/secondpath"
,
302
)
...
...
@@ -437,11 +440,16 @@ func TestJarCalls(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
c
.
Get
(
"http://firsthost.fake/nosetcookie"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
got
:=
jar
.
log
.
String
()
want
:=
`Cookies("http://firsthost.fake/")
SetCookie("http://firsthost.fake/", [name=val])
Cookies("http://secondhost.fake/secondpath")
SetCookie("http://secondhost.fake/secondpath", [namesecondpath=valsecondpath])
Cookies("http://firsthost.fake/nosetcookie")
`
if
got
!=
want
{
t
.
Errorf
(
"Got Jar calls:
\n
%s
\n
Want:
\n
%s"
,
got
,
want
)
...
...
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