niv / websocket.nim

websockets for nim
http://niv.github.io/websocket.nim/docs/0.1.1/websocket.html
Other
101 stars 25 forks source link

Problems with gdax websocket #27

Closed jamesalbert closed 6 years ago

jamesalbert commented 6 years ago

When trying to connect to GDAX's public websocket:

let ws = waitFor newAsyncWebsocket("wss://ws-feed.gdax.com:443/", 
                                   ctx=newContext(verifyMode=CVerifyNone))

I get Error: unhandled exception: server did not reply with a websocket upgrade: HTTP/1.1 520 Origin Error

Because I'm able to connect to wss://echo.websocket.org using the same function, and I'm able to connect using python (e.g. create_connection("wss://ws-feed.gdax.com:443/")), I suspect this is on websocket.nim's side. I've tried forking and fiddling around, but no dice

(I've tried it with both the production and sandbox feed)

edit: Forgot to post stats

update: looking back at this, I see this is a CloudFlare specific error code:

While the 520 error can be triggered by very unique and strange edge-case scenarios, they are generally caused by:

Connection resets (following a successful TCP handshake)
Headers exceed Cloudflare’s header size limit (over 8kb)
Empty response from origin
Invalid HTTP response
HTTP response missing response headers

But again, I was able to connect to it successfully in python and bash:

$ curl --include \
     --no-buffer \
     --header "Connection: Upgrade" \
     --header "Upgrade: websocket" \
     --header "Host: ws-feed.gdax.com:443" \
     --header "Origin: http://example.com:80" \
     --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
     --header "Sec-WebSocket-Version: 13" \
     https://ws-feed.gdax.com:443/

HTTP/2 200
date: Tue, 30 Jan 2018 08:00:27 GMT
content-type: text/plain
...
jamesalbert commented 6 years ago

thought I fixed it, I didn't