question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OkHttp 3.3.4-RC1 strange headers behavior with HTTP2 enabled

See original GitHub issue

I have updated from OkHttp 3.3.1 to 3.3.4-RC1 and then have faced strange issue: When I change request header value became merged with value from previous request (we have saw it on server side). It looks like this SESSION: <oldValue>, <newValue> instead of SESSION: <newValue>

This is exactly what we saw on server side - header has 2 different sessions in it 0ed91** and dc35275*: 'api-session': '0ed91033efc8950f18c85afa4e6537a3; 7RCbXBqq#zK=Tmfk03hsR7vaRra7jka8S8bMZh0fd1VJkq7?Ydtp=Y&uNNguGvoI; active; 1467802743964; 900000, dc352754a1606f641acac300a9d81adb; 7kch9FjctfxHSQb29NGytrQe7XICtn9WyPtmT2yKJ@s4ou0#Gikg&bvYfY@XxHN6; not-active; 1467802755394; 900000',

This happens only if Http2 enabled and client use OkHttp3 ver 3.3.4-RC1.

Server: Nginx 1.11.1 (Http2 Enabled) Client: Nexus 5 (Android 6.0.1) Connection: HTTPS (TLS1.2)

This is my interceptor used to add session header to each request and get new session header from each response.

Interceptor apiInterceptor = new Interceptor() {
            @Override
            public okhttp3.Response intercept(Chain chain) throws IOException {
                Request original = chain.request();

                Request.Builder builder = original.newBuilder()
                        .method(original.method(), original.body());

                if (model.getSession() != null) {
                    builder.addHeader(SESSION_HEADER, model.getSession().getHeader());
                }

                Request request = builder.build();

                okhttp3.Response response = chain.proceed(request);

                if (response.isSuccessful()) {
                    extractSession(response.headers());
                }

                return response;
            }
        };

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DASAR-zzcommented, Jul 12, 2016

@dave-r12 @swankjesse with 3.4.1 version this problem disappeared. Everything works as expected.

0reactions
dave-r12commented, Jul 10, 2016

This was likely caused by the bug fixed in #2715. @DASAR can you try version 3.4.1?

This test fails on 3.4.0:

  @Test public void dynamicTableHeaderIndexes() throws IOException {
    hpackWriter.writeHeaders(headerEntries("key", "value", "auth", "secret"));
    bytesIn.writeAll(bytesOut);
    hpackReader.readHeaders();
    assertEquals(headerEntries("key", "value", "auth", "secret"),
        hpackReader.getAndResetHeaderList());

    hpackWriter.writeHeaders(headerEntries("key", "value", "auth", "changedsecret"));
    bytesIn.writeAll(bytesOut);
    hpackReader.readHeaders();
    assertEquals(headerEntries("key", "value", "auth", "changedsecret"),
        hpackReader.getAndResetHeaderList());
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behavior when using HTTP Range along with OkHttp
I'm using OkHttp on my project for downloading a binary file on separate chunks using the Range HTTP header.
Read more >
3.x Change Log - OkHttp
To enable platform-specific TLS features OkHttp must detect whether it's running in a JVM ... Fix: Don't miss cancels when sending HTTP/2 request...
Read more >
RFC 7540 - Hypertext Transfer Protocol Version 2 (HTTP/2)
HTTP/2 enables a more efficient use of network resources and a reduced perception of latency by introducing header field compression and allowing multiple ......
Read more >
Response.Builder (OkHttp 3.3.1 API) - javadoc.io
Sets the header named name to value . Response.Builder · headers(Headers headers). Removes all headers on this builder and adds headers .
Read more >
A Guide to OkHttp - Baeldung
OkHttp is an efficient HTTP & HTTP/2 client for Android and Java applications. ... This happens after the response headers are ready.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found