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

Http logger always report HTTP 1.1 protocol even for HTTP 2 endpoints. #2247

Closed
lexer opened this issue Jan 15, 2016 · 0 comments
Closed

Http logger always report HTTP 1.1 protocol even for HTTP 2 endpoints. #2247

lexer opened this issue Jan 15, 2016 · 0 comments

Comments

@lexer
Copy link
Contributor

lexer commented Jan 15, 2016

To reproduce you can this android integration test:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest extends ApplicationTestCase<Application> {

    public ApplicationTest() {
        super(Application.class);
    }

    @Test
    public void testHttp2() throws IOException {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build();

        Request request = new Request.Builder()
                .url("https://twitter.com")
                .build();

        Response response = okHttpClient.newCall(request).execute();

        Protocol protocol = response.protocol();

        assertEquals(Protocol.HTTP_2, protocol);

        request = new Request.Builder()
                .url("https://twitter.com/download")
                .build();

        response = okHttpClient.newCall(request).execute();

        protocol = response.protocol();

        assertEquals(Protocol.HTTP_2, protocol);
    }
}

Test logs:

01-14 17:19:21.862 24439-24464/com.github.lexer.http2test I/TestRunner: run started: 1 tests
01-14 17:19:21.867 24439-24464/com.github.lexer.http2test I/TestRunner: started: testHttp2(com.github.lexer.http2test.ApplicationTest)
01-14 17:19:21.870 24439-24439/com.github.lexer.http2test I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
01-14 17:19:21.886 24439-24464/com.github.lexer.http2test D/OkHttp: --> GET https://twitter.com/ HTTP/1.1
01-14 17:19:23.525 24439-24464/com.github.lexer.http2test D/OkHttp: <-- 200  https://twitter.com/ (1637ms, -1-byte body)
01-14 17:19:50.231 24439-24464/com.github.lexer.http2test D/OkHttp: --> GET https://twitter.com/download HTTP/1.1
01-14 17:20:17.373 24439-24464/com.github.lexer.http2test D/OkHttp: <-- 200  https://twitter.com/download (27141ms, -1-byte body)
01-14 17:20:17.375 24439-24464/com.github.lexer.http2test I/TestRunner: finished: testHttp2(com.github.lexer.http2test.ApplicationTest)

I think something is probably wrong with how HttpLoggingInterceptor log things.

In all my tests: https://github.com/square/okhttp/blob/master/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.java#L151

connection is always null. So this code block:

    Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
    String requestStartMessage =
        "--> " + request.method() + ' ' + request.url() + ' ' + protocol(protocol);

Will always return HTTP 1.1

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

1 participant