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.

WebSocket sends Connection: "close" instead of "upgrade" on HTTPS

See original GitHub issue

What kind of issue is this?

  • Question. This issue tracker is not the place for questions. If you want to ask how to do something, or to understand why something isn’t working the way you expect it to, use Stack Overflow. https://stackoverflow.com/questions/tagged/okhttp

  • Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests get fixed. Here’s an example: https://gist.github.com/swankjesse/981fcae102f513eb13ed

  • Feature Request. Start by telling us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.

I’m using OKHTTP 3.9.1 and WebSocket always fails on https. So I printed the packet on server, and seems that for https, connection is close instead of upgrade. Same code runs well on http server (actually my https is under nginx it’s the same service on different ports). I noticed that there’s some “https upgrade problem” mentioned in okhttp-3.9.1 release notes, but not sure about the details. Any configuration needs to be done or anything please?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
artem-zinnatullincommented, Feb 6, 2018

It looks like misconfigured Ngnix. Make sure your location entry explicitly sets Upgrade and Connection headers. Both values can be either static or dynamic depending on requirements.

See this article https://www.nginx.com/blog/websocket-nginx/ and documentation https://nginx.org/en/docs/http/websocket.html for more info.

I’m using OKHTTP 3.9.1

According to pasted headers you’re using OkHttp 3.8.0

On Mon, Feb 5, 2018, 9:37 PM Leo notifications@github.com wrote:

I’ve printed headers from server.

http:

[authorization: “Bearer 3gMQkpHJ02iS/bgfMDwTtw==”, Sec-WebSocket-Version: “13”, Connection: “Upgrade”, User-Agent: “okhttp/3.8.0”, Upgrade: “websocket”, Sec-WebSocket-Key: “+0jpaxSfa1/nnBZG5/VKmw==”, Accept-Encoding: “gzip”, Host: “10.0.2.2:8080”]

https:

[X-Forwarded-For: “96.246.149.227”, Sec-WebSocket-Version: “13”, authorization: “Bearer 3gMQkpHJ02iS/bgfMDwTtw==”, Connection: “close”, Sec-WebSocket-Key: “J5q07bjo43UGwhxxxx+SHw==”, User-Agent: “okhttp/3.8.0”, X-Real-IP: “96.246.149.227”, Accept-Encoding: “gzip”, Host: “api.bxxo.live”]

Again, I’m not familiar with WebSocket so maybe I’m missing some basic things?

My Android code:

    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(Const.socketCast).build()
            .newBuilder().addHeader("authorization", UserRepository.mapToken.get("Authorization").toString()).build();
    socket = client.newWebSocket(request, listener);

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/okhttp/issues/3828#issuecomment-363316331, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7B3IeWtIrpAcVoZGiRz1aJJZll6_Qaks5tR-UFgaJpZM4R6Eqc .

1reaction
artem-zinnatullincommented, Feb 7, 2018

Great! Don’t forget to update OkHttp 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protocol upgrade mechanism - HTTP - MDN Web Docs - Mozilla
The HTTP/1.1 protocol provides a special mechanism that can be used to upgrade an already established connection to a different protocol, ...
Read more >
Websocket connection attempt fails, returns "Connection
Connection : upgrade, close requests that the server upgrade to (one of) the protocol(s) in the Upgrade header, or else to respond with ......
Read more >
WebSocket - The Modern JavaScript Tutorial
To open a websocket connection, we need to create new WebSocket using the ... https://javascript.info Connection: Upgrade Upgrade: websocket ...
Read more >
Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >
How to Close a WebSocket (Correctly) - Forty Years of Code
Either the client or the server sends a Close frame (WebSockets borrow a lot of TCP terminology, so you exchange data in “frames”), ......
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