tool_cb_hdr: only parse etag + content-disposition for 2xx
... and ignore them for other response codes. Reported-by: Harry Sintonen Closes #12866
This commit is contained in:
parent
5cc2b016c3
commit
75d79a4486
@ -105,12 +105,21 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
(void)fflush(heads->stream);
|
||||
}
|
||||
|
||||
curl_easy_getinfo(per->curl, CURLINFO_SCHEME, &scheme);
|
||||
scheme = proto_token(scheme);
|
||||
if((scheme == proto_http || scheme == proto_https)) {
|
||||
long response = 0;
|
||||
curl_easy_getinfo(per->curl, CURLINFO_RESPONSE_CODE, &response);
|
||||
|
||||
if(response/100 != 2)
|
||||
/* only care about these headers in 2xx responses */
|
||||
;
|
||||
/*
|
||||
* Write etag to file when --etag-save option is given.
|
||||
*/
|
||||
if(per->config->etag_save_file && etag_save->stream) {
|
||||
else if(per->config->etag_save_file && etag_save->stream &&
|
||||
/* match only header that start with etag (case insensitive) */
|
||||
if(curl_strnequal(str, "etag:", 5)) {
|
||||
checkprefix("etag:", str)) {
|
||||
const char *etag_h = &str[5];
|
||||
const char *eot = end - 1;
|
||||
if(*eot == '\n') {
|
||||
@ -128,7 +137,6 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This callback sets the filename where output shall be written when
|
||||
@ -137,11 +145,8 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
* Content-Disposition header specifying a filename property.
|
||||
*/
|
||||
|
||||
curl_easy_getinfo(per->curl, CURLINFO_SCHEME, &scheme);
|
||||
scheme = proto_token(scheme);
|
||||
if(hdrcbdata->honor_cd_filename &&
|
||||
(cb > 20) && checkprefix("Content-disposition:", str) &&
|
||||
(scheme == proto_http || scheme == proto_https)) {
|
||||
else if(hdrcbdata->honor_cd_filename &&
|
||||
(cb > 20) && checkprefix("Content-disposition:", str)) {
|
||||
const char *p = str + 20;
|
||||
|
||||
/* look for the 'filename=' parameter
|
||||
@ -179,7 +184,8 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
}
|
||||
|
||||
if(per->config->output_dir) {
|
||||
outs->filename = aprintf("%s/%s", per->config->output_dir, filename);
|
||||
outs->filename = aprintf("%s/%s", per->config->output_dir,
|
||||
filename);
|
||||
free(filename);
|
||||
if(!outs->filename)
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
@ -200,6 +206,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
if(!outs->stream && !tool_create_output_file(outs, per->config))
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
}
|
||||
}
|
||||
if(hdrcbdata->config->writeout) {
|
||||
char *value = memchr(ptr, ':', cb);
|
||||
if(value) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user