data->state.followlocation++; /* count location-followers */
if(data->set.http_auto_referer) {
+ CURLU *u;
+ char *referer;
+
/* We are asked to automatically set the previous URL as the referer
when we get the next URL. We pick the ->url field, which may or may
not be 100% correct */
data->state.referer_alloc = FALSE;
}
- data->state.referer = strdup(data->state.url);
- if(!data->state.referer)
+ /* Make a copy of the URL without crenditals and fragment */
+ u = curl_url();
+ if(!u)
+ return CURLE_OUT_OF_MEMORY;
+
+ uc = curl_url_set(u, CURLUPART_URL, data->state.url, 0);
+ if(!uc)
+ uc = curl_url_set(u, CURLUPART_FRAGMENT, NULL, 0);
+ if(!uc)
+ uc = curl_url_set(u, CURLUPART_USER, NULL, 0);
+ if(!uc)
+ uc = curl_url_set(u, CURLUPART_PASSWORD, NULL, 0);
+ if(!uc)
+ uc = curl_url_get(u, CURLUPART_URL, &referer, 0);
+
+ curl_url_cleanup(u);
+
+ if(uc || referer == NULL)
return CURLE_OUT_OF_MEMORY;
+
+ data->state.referer = referer;
data->state.referer_alloc = TRUE; /* yes, free this later */
}
}
--- /dev/null
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+referer
+followlocation
+--write-out
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 301 This is a weirdo text message swsclose\r
+Location: data/%TESTNUMBER0002.txt?coolsite=yes\r
+Content-Length: 62\r
+Connection: close\r
+\r
+This server reply is for testing a simple Location: following
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+Automatic referrer credential and anchor stripping check
+ </name>
+ <command>
+http://user:pass@%HOSTIP:%HTTPPORT/we/want/our/%TESTNUMBER#anchor --location --referer ';auto' --write-out '%{referer}\n'
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+52
+</errorcode>
+<protocol>
+GET /we/want/our/%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Authorization: Basic dXNlcjpwYXNz\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+GET /we/want/our/data/%TESTNUMBER0002.txt?coolsite=yes HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Authorization: Basic dXNlcjpwYXNz\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Referer: http://%HOSTIP:%HTTPPORT/we/want/our/%TESTNUMBER\r
+\r
+</protocol>
+<stdout>
+HTTP/1.1 301 This is a weirdo text message swsclose\r
+Location: data/%TESTNUMBER0002.txt?coolsite=yes\r
+Content-Length: 62\r
+Connection: close\r
+\r
+http://%HOSTIP:%HTTPPORT/we/want/our/%TESTNUMBER
+</stdout>
+</verify>
+</testcase>