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

Handshake Error on Android webview with Sec-WebSocket-Protocol #3418

Open
shahkaush opened this issue Apr 28, 2024 · 1 comment
Open

Handshake Error on Android webview with Sec-WebSocket-Protocol #3418

shahkaush opened this issue Apr 28, 2024 · 1 comment

Comments

@shahkaush
Copy link

Bug description:
When I connect the websocket on ESP8266 with Ethernet.h library (not the LWIP one), it works great from the Desktop chrome browser. But when the same page is accessed from Android webview, it shows this error in logcat:

"WebSocket connection to 'ws://192.168.102.123:81/' failed: Error during WebSocket handshake: Response must not include 'Sec-WebSocket-Protocol' header if not present in request: /537.36

To Reproduce:
Open a websocket from a page inside the Android webview
The following is seen in the handshake logs:
Line #0] GET / HTTP/1.1
[Line #1] Host: 192.168.1.40:81
[Line #2] Connection: Upgrade
[Line #3] Pragma: no-cache
[Line #4] Cache-Control: no-cache
[Line #5] Upgrade: websocket
[Line #6] Origin: http://vii.co.in
[Line #7] Sec-WebSocket-Version: 13
[Line #8] User-Agent: Mozilla/5.0 (Linux; Android 9; SMART TV Build/PPR2.180905.006.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Safari/537.36
[Line #9] Accept-Encoding: gzip, deflate
[Line #10] Accept-Language: en-US
[Line #11] X-Requested-With: com.viiui
[Line #12] Sec-WebSocket-Key: zucC9T5fkNmL6wvK3tuzcw==
[Line #13] Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
[Line #14]

Expected behavior:
The web socket should connect

Environment:

  • OS: Windows
  • OS version: 10
  • react-native version: AOSP Android (dont have the exact version)
  • react-native-webview version: don't have that data now
@shahkaush
Copy link
Author

Solution:

I comment out the following lines in WebSocketServer.cpp in the _acceptRequest function

//COMMENTED BY KAUSHAL

// if (protocol[0] != '\0') {
// // NOTE: Up to 26 characters for protocol value
// snprintf_P(
// buffer, sizeof(buffer), (PGM_P)F("Sec-WebSocket-Protocol: %s"), protocol);
// client.println(buffer);
// }

Then the android webview websocket works!

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

No branches or pull requests

1 participant