-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Empty Accept-Encoding: Header doesn't override CURLOPT_ACCEPT_ENCODING on 2nd request with reused handle #785
Comments
The problem here is that
So you're really asking for two mutually exclusive things in that request and it's not immediately clear which of the two instructions that should override the other... |
Could we perhaps make this clearer in the documentation? |
Perhaps it would help to mention that one may set CURLOPT_ACCEPT_ENCODING to a NULL pointer in order to disable it (both sending the header and auto decoding) in case it was previously enabled on the given easy handle. BTW, I find the statement "identity, which does nothing" to be a bit misleading, as setting 'identity' does in fact enable auto decoding (e.g. if the header was overridden, or if the server sends gzip despite what the client has specified) and regardless, sending the header with 'identity' only isn't exactly nothing. |
Ok, I committed an update to this man page, have a look at CURLOPT_ACCEPT_ENCODING for the new version. Better? Anything lacking now? |
Clarify that CURLOPT_ACCEPT_ENCODING has to be explicitly disabled only if it was previously enabled (as the default is NULL). Mention possible content-length mismatch with sum of bytes reported by write callbacks when auto decoding is enabled. See curl#785
Yea, but take a look at little adjustments: iboukris@7a329b8 |
Mention possible content-length mismatch with sum of bytes reported by write callbacks when auto decoding is enabled. See #785
Thanks! I merged the second part of that change. I'm not comfortable with adding the "if it was set to something else before you can disable it again with" text. That is sort of implied if you need to disable it, and I would rather not add that extra text for every man page description we have that tells how to switch an option back to default state. |
Make sense, thanks! |
@rcanavan, you happy with this explanation or are you looking for something else? |
Hmm, I've looked again at @rcanavan's example and gave it a quick run, and the behavior actually seem strange indeed. |
But again, you can't both set CURLOPT_ACCEPT_ENCODING (to non-NULL) and ask for disabling the header. |
But the doc of CURLOPT_HTTPHEADER says: And it does work as one would expect if a connection is not reused. |
Perhaps something like this makes it behave more deterministic? diff --git a/lib/http.c b/lib/http.c
index f3805cc..2a7280d 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1915,10 +1915,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
conn->allocptr.accept_encoding =
aprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]);
if(!conn->allocptr.accept_encoding)
return CURLE_OUT_OF_MEMORY;
}
+ else {
+ Curl_safefree(conn->allocptr.accept_encoding);
+ conn->allocptr.accept_encoding = NULL;
+ }
#ifdef HAVE_LIBZ
/* we only consider transfer-encoding magic if libz support is built-in */
if(!Curl_checkheaders(conn, "TE:") && |
This works, and it looks correct as well. |
That patch does indeed make libcurl behave consistently, not only accross reused connections, but also when adding values to Accept-Encoding: as opposed to trying to unset it. And it is exactly this consistency that I was looking for, and the assurance that other headers, when set first with a value via CURLOPT_HTTPHEADER and then unset, behave just as consistently when reusing a handle. |
Yeah sorry for overseeing the consistency argument originally. I've just merged this. Thanks both of you for your help! |
The test program below (modified from examples/httpcustomheader.c) attempts to send 2 requests to a host, and reuse the curl handle. On the second request, it attempts to disable CURLOPT_ACCEPT_ENCODING by explicitly setting the Accept-Encoding:-header without a value.
This works as expected (i.e. no Accept-Encoding header is sent in the request) only if a "fresh" handle is used or no previous request with that handle has ever actually sent a request with the Accept-Encoding header set via CURLOPT_ACCEPT_ENCODING.
The text was updated successfully, but these errors were encountered: