New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
curl_easy_nextheader returns null on all subsequent requests after having followed a redirect #9424
Labels
Comments
Thanks a lot for your report! Do you perhaps have a small stand-alone program we can run from our ends against a public URL to trigger the problem? |
My knowledge of C is limited, but I cobbled together something. I get linker errors when I try to run it, so I'm not 100% sure it's correct. #include "curl.h"
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
/*perform a request that involves redirection*/
curl_easy_setopt(curl, CURLOPT_URL, "https://nghttp2.org/httpbin/redirect/1");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
/*count the number of requests by reading the first header of each request. Works as expected. */
struct curl_header *h;
int count = 0;
int origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT|CURLH_1XX|CURLH_PSEUDO);
while((h = curl_easy_nextheader(curl, origins, count, NULL))) {
count++;
}
printf("count =%u\n",count ); /* count=2 */
/*perform another request.*/
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com");
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
/*count the number of requests again. Always get NULL back. */
count = 0;
while((h = curl_easy_nextheader(curl, origins, count, NULL))) {
count++;
}
printf("count =%u\n",count );/* count=0 */
curl_easy_cleanup(curl);
}
return 0;
} |
Excellent, I can reproduce what you have reported with this. |
jay
added a commit
to jay/curl
that referenced
this issue
Sep 7, 2022
Prior to this change linker errors would occur if curl_easy_header or curl_easy_nextheader was called from a C++ unit. Bug: curl#9424 (comment) Reported-by: Andrew Lambert Closes #xxxx
bagder
added a commit
that referenced
this issue
Sep 7, 2022
If not, reusing an easy handle to do a subsequent transfer would continue the counter from the previous invoke, which then would make use of the header API difficult/impossible as the request counter mismatched. Add libtest 1947 to verify. Reported-by: Andrew Lambert Fixes #9424
bagder
added a commit
that referenced
this issue
Sep 7, 2022
If not, reusing an easy handle to do a subsequent transfer would continue the counter from the previous invoke, which then would make use of the header API difficult/impossible as the request counter mismatched. Add libtest 1947 to verify. Reported-by: Andrew Lambert Fixes #9424
jay
added a commit
that referenced
this issue
Sep 8, 2022
Prior to this change linker errors would occur if curl_easy_header or curl_easy_nextheader was called from a C++ unit. Bug: #9424 (comment) Reported-by: Andrew Lambert Closes #9446
bagder
added a commit
that referenced
this issue
Sep 9, 2022
If not, reusing an easy handle to do a subsequent transfer would continue the counter from the previous invoke, which then would make use of the header API difficult/impossible as the request counter mismatched. Add libtest 1947 to verify. Reported-by: Andrew Lambert Fixes #9424
jquepi
pushed a commit
to jquepi/curl.1.555
that referenced
this issue
Oct 24, 2022
Prior to this change linker errors would occur if curl_easy_header or curl_easy_nextheader was called from a C++ unit. Bug: curl/curl#9424 (comment) Reported-by: Andrew Lambert Closes curl/curl#9446
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did this
I'm calling
curl_easy_nextheader
in a loop to count the number of requests in the previous transfer. This works until a transfer involves HTTP redirection. After the redirected request completes,curl_easy_nextheader
will work as expected. However, on all subsequent requestscurl_easy_nextheader
will return null if therequest
parameter is greater than -1.I expected the following
That
curl_easy_nextheader
would not be affected by previous transfers.curl/libcurl version
libcurl/7.85.0 OpenSSL/3.0.5 (Schannel) zlib/1.2.12 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.3 libssh2/1.10.0 nghttp2/1.49.0 ngtcp2/0.8.0 nghttp3/0.7.0 libgsasl/1.10.0
operating system
Windows 10 build 19044.1889
The text was updated successfully, but these errors were encountered: