← Commit list

2302acd928

Stefan Eissing
Stefan Eissing
2026-09-22
SUCCESS Duration: 409s

Subject

tool: cache header scheme

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

src/tool_cb_hdr.c+18 -18
@@ -432,7 +432,6 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
const char *str = ptr;
const size_t cb = size * nmemb;
const char *end = ptr + cb;
- const char *scheme = NULL;
bool cd_checked = FALSE;
if(!per->config)
@@ -451,6 +450,16 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
memset(outs->utf8seq, 0, sizeof(outs->utf8seq));
#endif
+ /* If the last header was empty, check scheme again as we follow
+ * protocol switches on redirects */
+ if(!per->out_scheme || per->was_last_header_empty) {
+ char *scheme;
+ curl_easy_getinfo(per->curl, CURLINFO_SCHEME, &scheme);
+ per->out_scheme = proto_token(scheme);
+ per->num_headers = 0;
+ }
+ per->was_last_header_empty = (ptr[0] == '\r' || ptr[0] == '\n');
+
/*
* Write header data when curl option --dump-header (-D) is given.
*/
@@ -466,9 +475,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
}
}
- curl_easy_getinfo(per->curl, CURLINFO_SCHEME, &scheme);
- scheme = proto_token(scheme);
- if((scheme == proto_http || scheme == proto_https)) {
+ if((per->out_scheme == proto_http || per->out_scheme == proto_https)) {
long response = 0;
curl_easy_getinfo(per->curl, CURLINFO_RESPONSE_CODE, &response);
@@ -498,20 +505,13 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
cd_checked = TRUE;
}
}
- if(hdrcbdata->config->writeout) {
- const char *value = memchr(ptr, ':', cb);
- if(value) {
- if(per->was_last_header_empty)
- per->num_headers = 0;
- per->was_last_header_empty = FALSE;
- per->num_headers++;
- }
- else if(ptr[0] == '\r' || ptr[0] == '\n')
- per->was_last_header_empty = TRUE;
- }
+
+ if(hdrcbdata->config->writeout && memchr(ptr, ':', cb))
+ per->num_headers++;
+
if(hdrcbdata->config->show_headers && !outs->out_null &&
- (scheme == proto_http || scheme == proto_https ||
- scheme == proto_rtsp || scheme == proto_file)) {
+ (per->out_scheme == proto_http || per->out_scheme == proto_https ||
+ per->out_scheme == proto_rtsp || per->out_scheme == proto_file)) {
/* bold headers only for selected protocols */
const char *value = NULL;
@@ -519,7 +519,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
bypass the content-disposition handling above. Do not open the output
file until the filename decision is complete. Only for HTTP(S). */
if(hdrcbdata->honor_cd_filename && !cd_checked &&
- (scheme == proto_http || scheme == proto_https))
+ (per->out_scheme == proto_http || per->out_scheme == proto_https))
return buffer_header(hdrcbdata, str, cb);
if(!outs->stream && !tool_create_output_file(outs, per->config))
src/tool_operate.c+1 -0
@@ -1431,6 +1431,7 @@ static CURLcode create_single(struct OperationConfig *config,
per->config = config;
per->curl = curl;
per->urlnum = u->num;
+ per->out_scheme = NULL;
/* default headers output stream is stdout */
heads = &per->heads;
src/tool_operate.h+1 -0
@@ -46,6 +46,7 @@ struct per_transfer {
char *url;
curl_off_t urlnum; /* the index of the given URL */
char *outfile;
+ const char *out_scheme; /* scheme of current header output */
int infd;
struct ProgressData progressbar;
struct OutStruct outs;