pyodide-http icon indicating copy to clipboard operation
pyodide-http copied to clipboard

httpx support

Open 0xMochan opened this issue 2 years ago • 5 comments

Leaving this issue here to think about httpx support. I hope to come back to this one day and take a crack at it. I think it should be relatively simple since httpx is written in a sans-io manner which theoretically means a fetch version would be relatively simple to accomplish.

0xMochan avatar Jul 11 '23 03:07 0xMochan

So, to fix this issue https://github.com/pyodide/pyodide/issues/4292 I'm currently trying to work on this: https://github.com/psymbio/pyodide-http and (some reference notes https://github.com/psymbio/httpx_adapter)

Check this file: https://github.com/psymbio/pyodide-http/blob/main/pyodide_http/_httpx.py

There's an issue I am stuck at: Pyodide's Request class has a timeout attribute but the httpx Request class doesn't. Can you look into the code.

psymbio avatar Nov 23 '23 08:11 psymbio

@koenvo Can you have a look at this - https://github.com/psymbio/pyodide-http/tree/main/pyodide_http

Also, I'm not sure whether it's correct - any guidance will be helpful.

psymbio avatar Nov 28 '23 09:11 psymbio

This is solved by using a custom transport layer and https://github.com/urllib3/urllib3/pull/3195. For the solution visit: https://github.com/encode/httpx/discussions/2994#discussioncomment-7806700.

psymbio avatar Dec 10 '23 13:12 psymbio

Here is an implementation that uses run_sync to syncify pyfetch. It don't support sync APIs if the js environment doesn't support JSPI. (Note that it is very easy for a website to support JSPI through origin trial)

  👉 A Live Demo

I wonder do you guys already did some work on using a custom layer to stream response in the sync API? I think psymbio/pyodide-http is almost there.

CNSeniorious000 avatar Aug 11 '24 20:08 CNSeniorious000