Skip to content
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

Content-Length missing if Vary is present #1675

Closed
dekuashe opened this issue May 26, 2015 · 5 comments
Closed

Content-Length missing if Vary is present #1675

dekuashe opened this issue May 26, 2015 · 5 comments

Comments

@dekuashe
Copy link

Both Response.header("Content-Length") and Response.body().contentLength() are empty if the "Vary" header is set in the response. In my test case, the exact Vary header was Vary: Accept-Encoding,User-Agent.
Edit: The response was not compressed or changed in any way other than the Vary header being present.

@swankjesse
Copy link
Member

Mind providing us a test case? Are you using the HttpURLConnection API?

@nfuller
Copy link
Collaborator

nfuller commented May 27, 2015

FYI: This looks similar to a report against Android. I asked a similar question there.

https://code.google.com/p/android/issues/detail?id=174737

@dekuashe
Copy link
Author

@nfuller That's my report, actually.

@swankjesse Sure, apologies for being short on details. Unfortunately though, I was testing against internal URLs so it won't help to have those, but I can give you the exact responses and some other details. And this is using v2.3.0.

First, this actually breaks in Glide as well if you wish to take a peek at how they're setting it up: https://github.com/bumptech/glide/blob/master/integration/okhttp/src/main/java/com/bumptech/glide/integration/okhttp/OkHttpStreamFetcher.java

As for my own testing, it's basically the following, using all defaults and the most basic setup possible:

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
    .url(mUrl)
    .build();
Response response = client.newCall(request).execute();
Log.d("VaryTest", "Vary: " + response.header("Vary"));
Log.d("VaryTest", "Content-Length: " + response.header("Content-Length"));

Without Vary, it looks like this:
D/VaryTest﹕ Vary: null
D/VaryTest﹕ Content-Length: 40256

With Vary, it looks like this:
D/VaryTest﹕ Vary: Accept-Encoding,User-Agent
D/VaryTest﹕ Content-Length: null

The same two calls with cURL, all headers included (curl -i).
Without Vary:
Date: Wed, 27 May 2015 13:22:29 GMT
Server: Apache
Last-Modified: Fri, 22 May 2015 04:50:24 GMT
ETag: "4204f0-9d40-516a465ec8400"
Accept-Ranges: bytes
Content-Length: 40256
Cache-Control: max-age=86400
Expires: Thu, 28 May 2015 13:22:29 GMT
Content-Type: image/webp

With Vary:
Date: Wed, 27 May 2015 13:21:08 GMT
Server: Apache
Last-Modified: Fri, 22 May 2015 04:50:24 GMT
ETag: "4204f0-9d40-516a465ec8400"
Accept-Ranges: bytes
Content-Length: 40256
Cache-Control: max-age=86400
Expires: Thu, 28 May 2015 13:21:08 GMT
Vary: Accept-Encoding,User-Agent
Content-Type: image/webp

Doing a diff on the output of both cURL calls shows no difference, so I know the file is being served by Apache the exact same way in both cases, of course the only difference being that one has the Vary header.

Is there anything else I can provide you with?

@dekuashe
Copy link
Author

I forgot to include it, but using response.body().contentLength() in the above example acts similarly.

@dekuashe
Copy link
Author

I realize I wasn't setting the Accept-Encoding header in the request in cURL, which does indeed make a difference in what was actually being served there (the server was using the old deflate module). Apologies. I guess this is one of those "d'oh" moments.

Working as intended.

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

No branches or pull requests

3 participants