ianharrigan / hxWebSockets

hxWebSockets - websockets for all haxe platforms
https://github.com/ianharrigan/hxWebSockets
81 stars 18 forks source link

it's seem not support Firefox when target hxcpp? #6

Closed sonygod closed 4 years ago

sonygod commented 5 years ago

it's seem not support Firefox when target hxcpp?but chrome can be connectd.

server:hxcpp

client:js

gepatto commented 4 years ago

I think that may be because Firefox has a value keep-alive, Upgrade for the Connection header (instead of just Upgrade like chrome) which is not handled here : https://github.com/ianharrigan/hxWebSockets/blob/93a1d8636ab23d6134c82c80f2ac22873935d14d/hx/ws/WebSocketHandler.hx#L46 you can add && httpRequest.headers.get(HttpHeader.CONNECTION) != "keep-alive, Upgrade" for a (temporary?) fix.

sonygod commented 4 years ago

thanks ,I'll take a look!

ianharrigan commented 4 years ago

So do we thing changing:

} else if (httpRequest.headers.get(HttpHeader.CONNECTION) != "Upgrade") {

to

} else if (httpRequest.headers.get(HttpHeader.CONNECTION).indexOf("Upgrade") == -1) {

will fix this?

gepatto commented 4 years ago

hmm yes that's a more elegant solution..

ianharrigan commented 4 years ago

That change has been made now... can we retest and close if working - ill make a haxelib release if all is well.

gepatto commented 4 years ago

I'll test right away.. Will confirm working or not..

ianharrigan commented 4 years ago

Thanks very much Patrick - much appreciated!

Ian

gepatto commented 4 years ago

Hmm unfortunately I'm getting errors, but I upgraded to haxe 4.0.0 (final) today, So the problems may be related to that.. Will investigate

gepatto commented 4 years ago

Ok, my bad. The change works. I was testing a regular http-call to 127.0.0.1:3000 instead of a webpage that opens a websocket (that works).

This will crash the server after a few calls wit the following error: Assertion failed: (bits == (allocated_var_bits & bits)), function assert_var, file lib/harfbuzz/src/hb-buffer-private.hh, line 166.

Maybe a regular http-request should return a default response? Or would that break something?

ianharrigan commented 4 years ago

I get:

image

When sending a normal http request from PostMan - are you using hashlink? Wonder why you dont get the same error

gepatto commented 4 years ago

I'm using cpp as a target.. Crash will only happen after a few (fast!) requests to 127.0.01:3000.

( I do however have a slight modification in WebSocketServer.hx, that uses a thread instead of adding to the MainLoop to have the server work in OpenFL , so maybe that's a problem)

this is the output.. crash happens after the 7th request

`INFO :: Starting server - 127.0.0.1:3000 (maxConnections: 10) DEBUG :: ID-1 :: New socket handler DEBUG :: ID-1 :: Adding to web server handler to list - total: 1 DEBUG :: ID-1 :: Bytes read: 354 DATA :: ID-1

GET / HTTP/1.1 Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Host: 127.0.0.1:3000 Accept-Language: en-US,en;q=0.5 Cache-Control: max-age=0 Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0


DATA :: ID-1

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-1 :: Closed DEBUG :: ID-1 :: Removing web server handler from list - total: 0 DEBUG :: ID-2 :: New socket handler DEBUG :: ID-2 :: Adding to web server handler to list - total: 1 DEBUG :: ID-2 :: Bytes read: 354 DATA :: ID-2

GET / HTTP/1.1 Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Host: 127.0.0.1:3000 Accept-Language: en-US,en;q=0.5 Cache-Control: max-age=0 Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0


DATA :: ID-2

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-2 :: Closed DEBUG :: ID-2 :: Removing web server handler from list - total: 0 DEBUG :: ID-3 :: New socket handler DEBUG :: ID-3 :: Adding to web server handler to list - total: 1 DEBUG :: ID-3 :: Bytes read: 354 DATA :: ID-3

GET / HTTP/1.1 Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Host: 127.0.0.1:3000 Accept-Language: en-US,en;q=0.5 Cache-Control: max-age=0 Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0


DATA :: ID-3

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-3 :: Closed DEBUG :: ID-3 :: Removing web server handler from list - total: 0 DEBUG :: ID-4 :: New socket handler DEBUG :: ID-4 :: Adding to web server handler to list - total: 1 DEBUG :: ID-4 :: Bytes read: 354 DATA :: ID-4

GET / HTTP/1.1 Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Host: 127.0.0.1:3000 Accept-Language: en-US,en;q=0.5 Cache-Control: max-age=0 Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0


DATA :: ID-4

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-4 :: Closed DEBUG :: ID-4 :: Removing web server handler from list - total: 0 DEBUG :: ID-5 :: New socket handler DEBUG :: ID-5 :: Adding to web server handler to list - total: 1 DEBUG :: ID-5 :: Bytes read: 354 DATA :: ID-5

GET / HTTP/1.1 Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Host: 127.0.0.1:3000 Accept-Language: en-US,en;q=0.5 Cache-Control: max-age=0 Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0


DATA :: ID-5

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-5 :: Closed DEBUG :: ID-5 :: Removing web server handler from list - total: 0 DEBUG :: ID-6 :: New socket handler DEBUG :: ID-6 :: Adding to web server handler to list - total: 1 DEBUG :: ID-6 :: Bytes read: 354 DATA :: ID-6

GET / HTTP/1.1 Upgrade-Insecure-Requests: 1 Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Host: 127.0.0.1:3000 Accept-Language: en-US,en;q=0.5 Cache-Control: max-age=0 Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0


DATA :: ID-6

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-6 :: Closed Assertion failed: (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE), function hb_shape_plan_execute, file ./lib/harfbuzz/src/hb-shape-plan.cc, line 334. `

ianharrigan commented 4 years ago

weird... it seems a little strange for sure... the assertion probably makes sense because you do get some bytes back that are probably not unicode, but why is your server expecting unicode anyway? Its very possible to just get back a load of bytes... maybe im reading the error wrong

EDIT: i would look into the threading too, that might be the root cause too

gepatto commented 4 years ago

It's not even always the same error. here's one from just 1 request to 127.0.0.1:3000 from chrome sorry about the formatting of these posts.. it's markdown formatting the debug output.

` INFO :: Starting server - 127.0.0.1:3000 (maxConnections: 10) DEBUG :: ID-1 :: New socket handler DEBUG :: ID-1 :: Adding to web server handler to list - total: 1 DEBUG :: ID-1 :: Bytes read: 505 DATA :: ID-1

GET / HTTP/1.1 Accept-Encoding: gzip, deflate, br Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3 Host: 127.0.0.1:3000 Sec-Fetch-Mode: navigate Sec-Fetch-User: ?1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36 Upgrade-Insecure-Requests: 1 Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 Connection: keep-alive Sec-Fetch-Site: none


DATA :: ID-1

HTTP/1.1 426 Upgrade Connection: close Sec-WebSocket-Version: 13 X-WebSocket-Reject-Reason: Unsupported websocket client version: null, Only version 13 is supported.


DEBUG :: ID-1 :: Closed Assertion failed: (0 == (allocated_var_bits & bits)), function allocate_var, file lib/harfbuzz/src/hb-buffer-private.hh, line 146. `

ianharrigan commented 4 years ago

I cant seem to make mine crash, which indicates it something to do with the harfbuzz lib... which is text a text rendering engine, correct? My Guess is the few bytes you do get back from the request are enough to kill that lib. That said, i would have expected an empty response back, so ill look into that anyway

gepatto commented 4 years ago

Ok, I will test removing all rendering from my testproject and just use trace()

EDIT: Yes that fixed the crash

ianharrigan commented 4 years ago

ok, what about putting that back in, and trying with the latest version? Ive made a fix that doesnt sent back a spurious \r\n - so would be interesting to see if that was indeed the cause of it

ianharrigan commented 4 years ago

Actually, ignore me, thats actually broken things completely :/

ianharrigan commented 4 years ago

OK - can you try the latest version with your text rendering? Would be intersting to see if that fixes the issue.

gepatto commented 4 years ago

Will do, and I'll go ahead and put my test-project (OpenFL) on github too.

gepatto commented 4 years ago

Still crashes. test project is here: https://github.com/gepatto/hxWebsocketOpenFL_test.git for an openfl project I use a thread rather than the mainloop because that will block. See readme.

I added an UrlRequest on a short timer, so you don't need a browser to make it crash it self.

ianharrigan commented 4 years ago

I think (maybe) the issue is that your change is creating a thread and then calling tick() from it, which is now in a different context, so any callbacks that happen may very well have bad results... ... what about using a timer instead of a thread? Or ENTER_FRAME? That should all run in the same thread, correct? Just to see if that is the issue.

gepatto commented 4 years ago

I think you may be right. And also we may be running 'out of scope' of this issue ;) I'll continue work to make it play nice with openfl and keep you informed.

ianharrigan commented 4 years ago

OK - cool - so are we happy to close this issue then?

gepatto commented 4 years ago

I am if you are.

gepatto commented 4 years ago

and thanks !!

ianharrigan commented 4 years ago

Cool - I am if you are. ;)

Thanks for the help testing it!