jczic / MicroWebSrv

A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWebSrv
MIT License
641 stars 116 forks source link

Websockets do not work if you access them from the browser under iOS #19

Closed vrubel closed 6 years ago

jczic commented 6 years ago

Hmm I'll test that... Strange :/

JK-de commented 6 years ago

Note : I have sometimes problems getting an answer from the websocket when the connection takes too long. The timeout is set to 500ms in JS at function onOpen(evt)

vrubel commented 6 years ago

In this case, it is the different behavior in browsers on the PC and in iOS. On a PC all works, in iOS a connection break.

jczic commented 6 years ago

Can you have a debugging information for iOS @vrubel ? I don't have an iPhone for the moment.

vrubel commented 6 years ago

WebSocket connection to 'ws://192.168.1.45/' failed: Invalid HTTP version string: HTTP/1.0

vrubel commented 6 years ago

` diff --git a/microWebSrv.py b/microWebSrv.py index 2f61358..c218a6f 100755 --- a/microWebSrv.py +++ b/microWebSrv.py @@ -545,7 +545,7 @@ class MicroWebSrv :

     def _writeFirstLine(self, code) :
         reason = self._responseCodes.get(code, ('Unknown reason', ))[0]

By the way, the effect is reproduced when using the PC version of the Safari browser.

jczic commented 6 years ago

Ok thank you very mutch, I'll see that 😊

jczic commented 6 years ago

Yes, I've updated the 1.0 to 1.1 version of HTTP and I've added a Content-Length header of 0 in the switching protocols headers... That's better for firefox ....! But I don't found the solution for safari, it's very strange because safari seem waits an header after the handshake response.

vrubel commented 6 years ago

I checked the safari work with the ws: //echo.websocket.org/ site. Perhaps Wireshark will help to identify the difference in traffic.

jczic commented 6 years ago

I've analysed too and websocket.org have the same code in they test :) But there is a problem with the end of the headers I think ... That's works anywhere (android, windows IE, Chrome Firefox, Mac Chrome, Firefox) but not in safari.... I don't understand for the moment :'(

2018-03-05 12:34 GMT+01:00 vrubel notifications@github.com:

I checked the safari work with the ws: //echo.websocket.org/ site. Perhaps Wireshark will help to identify the difference in traffic.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jczic/MicroWebSrv/issues/19#issuecomment-370392278, or mute the thread https://github.com/notifications/unsubscribe-auth/AAegLAR-iFQXpRVRZ7jCGg9iWhOxnHT8ks5tbSLXgaJpZM4SbE4S .

--

Sincèrement,

vrubel commented 6 years ago

I captured the servers' answers. Perhaps this will help you in your search for a reason.

image

bad.txt good.txt

bad.pcapng.zip good.pcapng.zip

Maybe there is a problem with this? image

JK-de commented 6 years ago

I assume that "Upgrade: websocket\r\n" have to be at last line

jczic commented 6 years ago

Yes I've found :) That's works now ! it's a bug with the base64 encoder... I've pushed the fix ;)

jczic commented 6 years ago

Thank you for this report 👍