int count = 0;
if(data->cookies && data->state.cookie_engine) {
+ const char *host = data->state.aptr.cookiehost ?
+ data->state.aptr.cookiehost : conn->host.name;
+ const bool secure_context =
+ conn->handler->protocol&CURLPROTO_HTTPS ||
+ strcasecompare("localhost", host) ||
+ !strcmp(host, "127.0.0.1") ||
+ !strcmp(host, "[::1]") ? TRUE : FALSE;
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
- co = Curl_cookie_getlist(data->cookies,
- data->state.aptr.cookiehost?
- data->state.aptr.cookiehost:
- conn->host.name,
- data->state.up.path,
- (conn->handler->protocol&CURLPROTO_HTTPS)?
- TRUE:FALSE);
+ co = Curl_cookie_getlist(data->cookies, host, data->state.up.path,
+ secure_context);
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
if(co) {
#if !defined(CURL_DISABLE_COOKIES)
else if(data->cookies && data->state.cookie_engine &&
checkprefix("Set-Cookie:", headp)) {
+ /* If there is a custom-set Host: name, use it here, or else use real peer
+ host name. */
+ const char *host = data->state.aptr.cookiehost?
+ data->state.aptr.cookiehost:conn->host.name;
+ const bool secure_context =
+ conn->handler->protocol&CURLPROTO_HTTPS ||
+ strcasecompare("localhost", host) ||
+ !strcmp(host, "127.0.0.1") ||
+ !strcmp(host, "[::1]") ? TRUE : FALSE;
+
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE,
CURL_LOCK_ACCESS_SINGLE);
- Curl_cookie_add(data,
- data->cookies, TRUE, FALSE,
- headp + strlen("Set-Cookie:"),
- /* If there is a custom-set Host: name, use it
- here, or else use real peer host name. */
- data->state.aptr.cookiehost?
- data->state.aptr.cookiehost:conn->host.name,
- data->state.up.path,
- (conn->handler->protocol&CURLPROTO_HTTPS)?
- TRUE:FALSE);
+ Curl_cookie_add(data, data->cookies, TRUE, FALSE,
+ headp + strlen("Set-Cookie:"), host,
+ data->state.up.path, secure_context);
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
#endif
Funny-head: yesyes\r
%if !hyper
Set-Cookie: foobar=name; domain=anything.com; path=/ ; secure\r
-Set-Cookie:ismatch=this ; domain=127.0.0.1; path=/silly/\r
-Set-Cookie: overwrite=this ; domain=127.0.0.1; path=/overwrite/\r
-Set-Cookie: overwrite=this2 ; domain=127.0.0.1; path=/overwrite\r
-Set-Cookie: sec1value=secure1 ; domain=127.0.0.1; path=/secure1/ ; secure\r
-Set-Cookie: sec2value=secure2 ; domain=127.0.0.1; path=/secure2/ ; secure=\r
-Set-Cookie: sec3value=secure3 ; domain=127.0.0.1; path=/secure3/ ; secure=\r
-Set-Cookie: sec4value=secure4 ; secure=; domain=127.0.0.1; path=/secure4/ ; \r
-Set-Cookie: sec5value=secure5 ; secure; domain=127.0.0.1; path=/secure5/ ; \r
-Set-Cookie: sec6value=secure6 ; secure ; domain=127.0.0.1; path=/secure6/ ; \r
-Set-Cookie: sec7value=secure7 ; secure ; domain=127.0.0.1; path=/secure7/ ; \r
-Set-Cookie: sec8value=secure8 ; secure= ; domain=127.0.0.1; path=/secure8/ ; \r
-Set-Cookie: secure=very1 ; secure=; domain=127.0.0.1; path=/secure9/; \r
-Set-Cookie: httpo1=value1 ; domain=127.0.0.1; path=/p1/; httponly\r
-Set-Cookie: httpo2=value2 ; domain=127.0.0.1; path=/p2/; httponly=\r
-Set-Cookie: httpo3=value3 ; httponly; domain=127.0.0.1; path=/p3/;\r
-Set-Cookie: httpo4=value4 ; httponly=; domain=127.0.0.1; path=/p4/; \r
-Set-Cookie: httponly=myvalue1 ; domain=127.0.0.1; path=/p4/; httponly\r
-Set-Cookie: httpandsec=myvalue2 ; domain=127.0.0.1; path=/p4/; httponly; secure\r
-Set-Cookie: httpandsec2=myvalue3; domain=127.0.0.1; path=/p4/; httponly=; secure\r
-Set-Cookie: httpandsec3=myvalue4 ; domain=127.0.0.1; path=/p4/; httponly; secure=\r
-Set-Cookie: httpandsec4=myvalue5 ; domain=127.0.0.1; path=/p4/; httponly=; secure=\r
-Set-Cookie: httpandsec5=myvalue6 ; domain=127.0.0.1; path=/p4/; secure; httponly=\r
-Set-Cookie: httpandsec6=myvalue7 ; domain=127.0.0.1; path=/p4/; secure=; httponly=\r
-Set-Cookie: httpandsec7=myvalue8 ; domain=127.0.0.1; path=/p4/; secure; httponly\r
-Set-Cookie: httpandsec8=myvalue9; domain=127.0.0.1; path=/p4/; secure=; httponly\r
-Set-Cookie: partmatch=present; domain=127.0.0.1 ; path=/;\r
+Set-Cookie:ismatch=this ; domain=test31.curl; path=/silly/\r
+Set-Cookie: overwrite=this ; domain=test31.curl; path=/overwrite/\r
+Set-Cookie: overwrite=this2 ; domain=test31.curl; path=/overwrite\r
+Set-Cookie: sec1value=secure1 ; domain=test31.curl; path=/secure1/ ; secure\r
+Set-Cookie: sec2value=secure2 ; domain=test31.curl; path=/secure2/ ; secure=\r
+Set-Cookie: sec3value=secure3 ; domain=test31.curl; path=/secure3/ ; secure=\r
+Set-Cookie: sec4value=secure4 ; secure=; domain=test31.curl; path=/secure4/ ; \r
+Set-Cookie: sec5value=secure5 ; secure; domain=test31.curl; path=/secure5/ ; \r
+Set-Cookie: sec6value=secure6 ; secure ; domain=test31.curl; path=/secure6/ ; \r
+Set-Cookie: sec7value=secure7 ; secure ; domain=test31.curl; path=/secure7/ ; \r
+Set-Cookie: sec8value=secure8 ; secure= ; domain=test31.curl; path=/secure8/ ; \r
+Set-Cookie: secure=very1 ; secure=; domain=test31.curl; path=/secure9/; \r
+Set-Cookie: httpo1=value1 ; domain=test31.curl; path=/p1/; httponly\r
+Set-Cookie: httpo2=value2 ; domain=test31.curl; path=/p2/; httponly=\r
+Set-Cookie: httpo3=value3 ; httponly; domain=test31.curl; path=/p3/;\r
+Set-Cookie: httpo4=value4 ; httponly=; domain=test31.curl; path=/p4/; \r
+Set-Cookie: httponly=myvalue1 ; domain=test31.curl; path=/p4/; httponly\r
+Set-Cookie: httpandsec=myvalue2 ; domain=test31.curl; path=/p4/; httponly; secure\r
+Set-Cookie: httpandsec2=myvalue3; domain=test31.curl; path=/p4/; httponly=; secure\r
+Set-Cookie: httpandsec3=myvalue4 ; domain=test31.curl; path=/p4/; httponly; secure=\r
+Set-Cookie: httpandsec4=myvalue5 ; domain=test31.curl; path=/p4/; httponly=; secure=\r
+Set-Cookie: httpandsec5=myvalue6 ; domain=test31.curl; path=/p4/; secure; httponly=\r
+Set-Cookie: httpandsec6=myvalue7 ; domain=test31.curl; path=/p4/; secure=; httponly=\r
+Set-Cookie: httpandsec7=myvalue8 ; domain=test31.curl; path=/p4/; secure; httponly\r
+Set-Cookie: httpandsec8=myvalue9; domain=test31.curl; path=/p4/; secure=; httponly\r
+Set-Cookie: partmatch=present; domain=test31.curl ; path=/;\r
Set-Cookie:eat=this; domain=moo.foo.moo;\r
Set-Cookie: eat=this-too; domain=.foo.moo;\r
Set-Cookie: nodomainnovalue\r
Set-Cookie: test=yes; domain=foo.com; expires=Sat Feb 2 11:56:27 GMT 2030\r
Set-Cookie: test2=yes; domain=se; expires=Sat Feb 2 11:56:27 GMT 2030\r
Set-Cookie: magic=yessir; path=/silly/; HttpOnly\r
-Set-Cookie: blexp=yesyes; domain=127.0.0.1; domain=127.0.0.1; expiry=totally bad;\r
+Set-Cookie: blexp=yesyes; domain=test31.curl; domain=test31.curl; expiry=totally bad;\r
Set-Cookie: partialip=nono; domain=.0.0.1;\r
Set-Cookie: withspaces= yes within and around ;\r
Set-Cookie: withspaces2 =before equals;\r
Set-Cookie: securewithspace=after ; secure =\r
%else
Set-Cookie: foobar=name; domain=anything.com; path=/ ; secure\r
-Set-Cookie: ismatch=this ; domain=127.0.0.1; path=/silly/\r
-Set-Cookie: overwrite=this ; domain=127.0.0.1; path=/overwrite/\r
-Set-Cookie: overwrite=this2 ; domain=127.0.0.1; path=/overwrite\r
-Set-Cookie: sec1value=secure1 ; domain=127.0.0.1; path=/secure1/ ; secure\r
-Set-Cookie: sec2value=secure2 ; domain=127.0.0.1; path=/secure2/ ; secure=\r
-Set-Cookie: sec3value=secure3 ; domain=127.0.0.1; path=/secure3/ ; secure=\r
-Set-Cookie: sec4value=secure4 ; secure=; domain=127.0.0.1; path=/secure4/ ;\r
-Set-Cookie: sec5value=secure5 ; secure; domain=127.0.0.1; path=/secure5/ ;\r
-Set-Cookie: sec6value=secure6 ; secure ; domain=127.0.0.1; path=/secure6/ ;\r
-Set-Cookie: sec7value=secure7 ; secure ; domain=127.0.0.1; path=/secure7/ ;\r
-Set-Cookie: sec8value=secure8 ; secure= ; domain=127.0.0.1; path=/secure8/ ;\r
-Set-Cookie: secure=very1 ; secure=; domain=127.0.0.1; path=/secure9/;\r
-Set-Cookie: httpo1=value1 ; domain=127.0.0.1; path=/p1/; httponly\r
-Set-Cookie: httpo2=value2 ; domain=127.0.0.1; path=/p2/; httponly=\r
-Set-Cookie: httpo3=value3 ; httponly; domain=127.0.0.1; path=/p3/;\r
-Set-Cookie: httpo4=value4 ; httponly=; domain=127.0.0.1; path=/p4/;\r
-Set-Cookie: httponly=myvalue1 ; domain=127.0.0.1; path=/p4/; httponly\r
-Set-Cookie: httpandsec=myvalue2 ; domain=127.0.0.1; path=/p4/; httponly; secure\r
-Set-Cookie: httpandsec2=myvalue3; domain=127.0.0.1; path=/p4/; httponly=; secure\r
-Set-Cookie: httpandsec3=myvalue4 ; domain=127.0.0.1; path=/p4/; httponly; secure=\r
-Set-Cookie: httpandsec4=myvalue5 ; domain=127.0.0.1; path=/p4/; httponly=; secure=\r
-Set-Cookie: httpandsec5=myvalue6 ; domain=127.0.0.1; path=/p4/; secure; httponly=\r
-Set-Cookie: httpandsec6=myvalue7 ; domain=127.0.0.1; path=/p4/; secure=; httponly=\r
-Set-Cookie: httpandsec7=myvalue8 ; domain=127.0.0.1; path=/p4/; secure; httponly\r
-Set-Cookie: httpandsec8=myvalue9; domain=127.0.0.1; path=/p4/; secure=; httponly\r
-Set-Cookie: partmatch=present; domain=127.0.0.1 ; path=/;\r
+Set-Cookie: ismatch=this ; domain=test31.curl; path=/silly/\r
+Set-Cookie: overwrite=this ; domain=test31.curl; path=/overwrite/\r
+Set-Cookie: overwrite=this2 ; domain=test31.curl; path=/overwrite\r
+Set-Cookie: sec1value=secure1 ; domain=test31.curl; path=/secure1/ ; secure\r
+Set-Cookie: sec2value=secure2 ; domain=test31.curl; path=/secure2/ ; secure=\r
+Set-Cookie: sec3value=secure3 ; domain=test31.curl; path=/secure3/ ; secure=\r
+Set-Cookie: sec4value=secure4 ; secure=; domain=test31.curl; path=/secure4/ ;\r
+Set-Cookie: sec5value=secure5 ; secure; domain=test31.curl; path=/secure5/ ;\r
+Set-Cookie: sec6value=secure6 ; secure ; domain=test31.curl; path=/secure6/ ;\r
+Set-Cookie: sec7value=secure7 ; secure ; domain=test31.curl; path=/secure7/ ;\r
+Set-Cookie: sec8value=secure8 ; secure= ; domain=test31.curl; path=/secure8/ ;\r
+Set-Cookie: secure=very1 ; secure=; domain=test31.curl; path=/secure9/;\r
+Set-Cookie: httpo1=value1 ; domain=test31.curl; path=/p1/; httponly\r
+Set-Cookie: httpo2=value2 ; domain=test31.curl; path=/p2/; httponly=\r
+Set-Cookie: httpo3=value3 ; httponly; domain=test31.curl; path=/p3/;\r
+Set-Cookie: httpo4=value4 ; httponly=; domain=test31.curl; path=/p4/;\r
+Set-Cookie: httponly=myvalue1 ; domain=test31.curl; path=/p4/; httponly\r
+Set-Cookie: httpandsec=myvalue2 ; domain=test31.curl; path=/p4/; httponly; secure\r
+Set-Cookie: httpandsec2=myvalue3; domain=test31.curl; path=/p4/; httponly=; secure\r
+Set-Cookie: httpandsec3=myvalue4 ; domain=test31.curl; path=/p4/; httponly; secure=\r
+Set-Cookie: httpandsec4=myvalue5 ; domain=test31.curl; path=/p4/; httponly=; secure=\r
+Set-Cookie: httpandsec5=myvalue6 ; domain=test31.curl; path=/p4/; secure; httponly=\r
+Set-Cookie: httpandsec6=myvalue7 ; domain=test31.curl; path=/p4/; secure=; httponly=\r
+Set-Cookie: httpandsec7=myvalue8 ; domain=test31.curl; path=/p4/; secure; httponly\r
+Set-Cookie: httpandsec8=myvalue9; domain=test31.curl; path=/p4/; secure=; httponly\r
+Set-Cookie: partmatch=present; domain=test31.curl ; path=/;\r
Set-Cookie: eat=this; domain=moo.foo.moo;\r
Set-Cookie: eat=this-too; domain=.foo.moo;\r
Set-Cookie: nodomainnovalue\r
Set-Cookie: test=yes; domain=foo.com; expires=Sat Feb 2 11:56:27 GMT 2030\r
Set-Cookie: test2=yes; domain=se; expires=Sat Feb 2 11:56:27 GMT 2030\r
Set-Cookie: magic=yessir; path=/silly/; HttpOnly\r
-Set-Cookie: blexp=yesyes; domain=127.0.0.1; domain=127.0.0.1; expiry=totally bad;\r
+Set-Cookie: blexp=yesyes; domain=test31.curl; domain=test31.curl; expiry=totally bad;\r
Set-Cookie: partialip=nono; domain=.0.0.1;\r
Set-Cookie: withspaces= yes within and around ;\r
Set-Cookie: withspaces2 =before equals;\r
TZ=GMT
</setenv>
<command>
-http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -b none -c log/jar%TESTNUMBER.txt
+http://test31.curl:%HTTPPORT/we/want/%TESTNUMBER -b none -c log/jar%TESTNUMBER.txt --resolve test31.curl:%HTTPPORT:127.0.0.1
</command>
<precheck>
perl -e "print 'Test requires default test server host' if ( '%HOSTIP' ne '127.0.0.1' );"
<verify>
<protocol>
GET /we/want/%TESTNUMBER HTTP/1.1\r
-Host: %HOSTIP:%HTTPPORT\r
+Host: test31.curl:%HTTPPORT\r
User-Agent: curl/%VERSION\r
Accept: */*\r
\r
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
-127.0.0.1 FALSE /we/want/ FALSE 0 prespace yes before
-127.0.0.1 FALSE /we/want/ FALSE 0 withspaces2 before equals
-127.0.0.1 FALSE /we/want/ FALSE 0 withspaces yes within and around
-127.0.0.1 FALSE /we/want/ FALSE 0 blexp yesyes
-#HttpOnly_127.0.0.1 FALSE /silly/ FALSE 0 magic yessir
-127.0.0.1 FALSE /we/want/ FALSE 2118138987 nodomain value
-127.0.0.1 FALSE / FALSE 0 partmatch present
-#HttpOnly_127.0.0.1 FALSE /p4/ FALSE 0 httponly myvalue1
-#HttpOnly_127.0.0.1 FALSE /p4/ FALSE 0 httpo4 value4
-#HttpOnly_127.0.0.1 FALSE /p3/ FALSE 0 httpo3 value3
-#HttpOnly_127.0.0.1 FALSE /p2/ FALSE 0 httpo2 value2
-#HttpOnly_127.0.0.1 FALSE /p1/ FALSE 0 httpo1 value1
-127.0.0.1 FALSE /overwrite FALSE 0 overwrite this2
-127.0.0.1 FALSE /silly/ FALSE 0 ismatch this
+test31.curl FALSE /we/want/ FALSE 0 prespace yes before
+test31.curl FALSE /we/want/ FALSE 0 withspaces2 before equals
+test31.curl FALSE /we/want/ FALSE 0 withspaces yes within and around
+.test31.curl TRUE /we/want/ FALSE 0 blexp yesyes
+#HttpOnly_test31.curl FALSE /silly/ FALSE 0 magic yessir
+test31.curl FALSE /we/want/ FALSE 2118138987 nodomain value
+.test31.curl TRUE / FALSE 0 partmatch present
+#HttpOnly_.test31.curl TRUE /p4/ FALSE 0 httponly myvalue1
+#HttpOnly_.test31.curl TRUE /p4/ FALSE 0 httpo4 value4
+#HttpOnly_.test31.curl TRUE /p3/ FALSE 0 httpo3 value3
+#HttpOnly_.test31.curl TRUE /p2/ FALSE 0 httpo2 value2
+#HttpOnly_.test31.curl TRUE /p1/ FALSE 0 httpo1 value1
+.test31.curl TRUE /overwrite FALSE 0 overwrite this2
+.test31.curl TRUE /silly/ FALSE 0 ismatch this
</file>
</verify>
</testcase>