szmarczak / http2-wrapper

Use HTTP/2 the same way like HTTP/1
MIT License
240 stars 18 forks source link

Proxy Question #46

Closed yovanoc closed 3 years ago

yovanoc commented 4 years ago

Follow up on #43

curl -XPOST -v "https://httpbin.org/anything" --proxy "http://username:password@ip:port" --http2

Result: https://gist.github.com/yovanoc/e316e8f3e965a1a2b7e1d29de76ff92c

H2 over H1 is working with curl but not here, maybe the proxy url starting with http and not https?

szmarczak commented 4 years ago

I think I know the culprit. Fixing now. Thanks for reporting, I really appreciate it! <3

szmarczak commented 4 years ago

Basically new URL('https://google.com/httpbin.org:443').pathname gives /httpbin.org:443 instead of httpbin.org:443. Which results in an invalid CONNECT path. Node.js should fix that.

szmarczak commented 4 years ago

Fixed. Please let me know if it works or not :)

yovanoc commented 4 years ago

Ahah perfect now ! Big thanks ! When these agents will be available to work with Got ?

I have now to make websockets working with http2 I think it will be harder :/

yovanoc commented 4 years ago

If we put the h2-over-h1 agent on engine.io-client options, I think it could work. Waiting the release of these agents. Big thanks

tested and of course: TypeError [ERR_INVALID_ARG_TYPE]: The "options.agent" property must be one of Agent-like Object, undefined, or false. Received an instance of m

i will have to use raw websocket then implements engine.io on top on my own

szmarczak commented 4 years ago

i will have to use raw websocket then implements engine.io on top on my own

Well, you aren't alone, I will create an example on how to do this too :) That's quite common use-case.

yovanoc commented 4 years ago

Really you can do this? :0 Because I really don’t know how to do this .. I have to connect to a primus server with engine.io as transport behind http2 and it’s not easy

szmarczak commented 4 years ago

No, I will just create an example on how to use the ws package with http2-wrapper.

yovanoc commented 4 years ago

Oh right ! Good don’t have questions anymore :)

szmarczak commented 4 years ago

I've done more polishing, will create a ws example tomorrow.

yovanoc commented 4 years ago

Waw amazing bro! So we will be able to use proxy through http2-wrapper for the ws?

szmarczak commented 4 years ago

Theoretically (based on https://github.com/jasnell/http2ws/blob/master/http2ws.js) this should work 536e0786659e307688b59a9ae8edb7ab7b8000e7 but I wasn't able to find any HTTP/2 server that would support WebSockets, so couldn't test it.

szmarczak commented 3 years ago

The proxies should work now. Closing. Don't hesitate to ask any questions if you have any :)

yovanoc commented 3 years ago

Hello, yes I try again and I got

CONNECTED!
RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear
    at Receiver.getInfo (/Users/devchris/Library/Mobile Documents/com~apple~CloudDocs/Documents/code/nodejs/http2-wrapper/node_modules/ws/lib/receiver.js:171:14)
    at Receiver.startLoop (/Users/devchris/Library/Mobile Documents/com~apple~CloudDocs/Documents/code/nodejs/http2-wrapper/node_modules/ws/lib/receiver.js:131:22)
    at Receiver._write (/Users/devchris/Library/Mobile Documents/com~apple~CloudDocs/Documents/code/nodejs/http2-wrapper/node_modules/ws/lib/receiver.js:78:10)
    at writeOrBuffer (_stream_writable.js:352:12)
    at Receiver.Writable.write (_stream_writable.js:303:10)
    at ClientHttp2Stream.socketOnData (/Users/devchris/Library/Mobile Documents/com~apple~CloudDocs/Documents/code/nodejs/http2-wrapper/node_modules/ws/lib/websocket.js:900:35)
    at ClientHttp2Stream.emit (events.js:315:20)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:284:9)
    at ClientHttp2Stream.Readable.push (_stream_readable.js:223:10) {
  [Symbol(status-code)]: 1002
}
DISCONNECTED!
szmarczak commented 3 years ago

@yovanoc Can you please open another issue for this?

szmarczak commented 3 years ago

@yovanoc I've fixed the WebSockets POC. PTAL.

yovanoc commented 3 years ago

Hello, I checked and still the issue :/