Skip to content

Check if entity's stream is really compressed. #583

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

Closed
wants to merge 1 commit into from

Conversation

ecdpalma
Copy link

@ecdpalma ecdpalma commented Jun 3, 2014

(I know this use case is absolutely uncommon, but maybe someone may need the same thing.)

One of our clients has a server returning 404 errors with
Content-Encoding=gzip, but the content itself is not compressed, causing
'new GZIPInputStream' in InflatingEntity#getContent to throw an
IOException.

When using FileAsyncHttpResponseHandler, for some reason we couldn't
find out, after some requests with the wrong 404 response,
AsyncHttpClient was getting stuck and after some time it raised
ConnectionPoolTimeoutException. This wasn't happening when the
BaseJsonHttpResponseHandler was being used.

One of our clients has a server returning 404 errors with
Content-Encoding=gzip, but the content itself is not compressed, causing
'new GZIPInputStream' in  InflatingEntity#getContent to throw an
IOException.

When using FileAsyncHttpResponseHandler, for some reason we couldn't
find out, after some requests with the wrong 404 response,
AsyncHttpClient was getting stuck and after some time it raised
ConnectionPoolTimeoutException. This wasn't happening when the
BaseJsonHttpResponseHandler was being used.
@fineswap
Copy link
Contributor

fineswap commented Jun 3, 2014

@ecdpalma

I am bewildered as to why we need the library to support non-standard servers? This rests on the server's administrator shoulders, not the clients. If the server sends a content type (willingly) indicating a compressed content, then the content must be compressed. If the server wants to send uncompressed content, the content type must reflect that.

I'm afraid that this is a special case; you'll have to extend AsyncHttpClient class and implement it for your client.

@fineswap fineswap closed this Jun 3, 2014
@fineswap fineswap added this to the 1.4.5 milestone Jun 3, 2014
@fineswap fineswap self-assigned this Jun 3, 2014
@smarek smarek reopened this Jun 3, 2014
@smarek
Copy link
Member

smarek commented Jun 3, 2014

I'd be willing to merge that, because it'd be better to have it working with warning (which is the only thing I'm missing) than to have them grope in the dark (I'm talking about the way this problem expresses itself).

So the question is, what will this change do, will it slow down the processing of each request? If so how much? @ecdpalma thanks for the pull request, and please, do me a favor and put this through some stress testing, and let us know how large performance change will occur, because change in such place shall not be underestimated.

@fineswap
We know this is un-common situation, we have few options:

  1. Merge it as-is, but I'd like to add warning log output, saying "Server stated compressed response, but it is being send uncompressed"
  2. Add it as optional fix, where you could either enable or disable it via AsyncHttpClient interface (such as disableStrictCompressedResponseCheck)

@fineswap
Copy link
Contributor

fineswap commented Jun 3, 2014

Well, if there's a toggle to enable/disable this functionality (I should have thought of that myself) then it's a welcome addition.

However, I believe that when the toggle is in place, then other aspects of the library where compression is being utilized should also benefit from this (rather than consume the content as being compressed).

With this being said, maybe it'd be best to create a standalone method, maybe a static function even, to test if an InputStream is compressed or not. A utility function, much like silentCloseInputStream().

@smarek
Copy link
Member

smarek commented Jun 7, 2014

@ecdpalma again, thanks for suggestion, I've just included it in modified version: 25023d8

@fineswap review please?

@smarek smarek closed this Jun 7, 2014
@smarek smarek removed the wontfix label Jun 7, 2014
@fineswap
Copy link
Contributor

fineswap commented Jun 7, 2014

@smarek
I'll review it and fix as necessary. Good job guys!

@ecdpalma
Copy link
Author

ecdpalma commented Jun 8, 2014

Sorry for the delay on answering, guys. It's been a tough week.

I agree completely with @fineswap's first comment. I have a very particular case for this, and if it were under my control, I would solve it in the server.

On the patch performance: I couldn't find any problem affecting user experience.

One doubt that remains is: why was the HttpClient getting stuck when using the FileAsyncHttpResponseHandler and not with BaseJsonHttpResponseHandler (please see the last paragraph in my first comment in this PR)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants