micropython / micropython-lib

Core Python libraries ported to MicroPython
Other
2.3k stars 980 forks source link

uaiohttpclient: Implement parsing and handling HTTP auth URLs #867

Open mirko opened 1 month ago

mirko commented 1 month ago

Allows HTTP Basic Auth URLs being passed, parsed and handled correctly to authorise against a server expecting that. This is a simplification, completely ignoring if the server supports or asks for HTTP Basic Auth. We simply format and set the header if the URL indicates so.

This also fixes parsing URLs containing a colon (':') /not/ indicating a custom port (but e.g. the seperation between user and password as part of the HTTP Basic Auth credentials).

Previously, the lib died ungracefully when parsing an URL containing HTTP Basic Auth credentials, as it was always expecting at most only one colon (':') and also the part coming afterwards being neccesarily a number (port).

dpgeorge commented 3 weeks ago

Thanks for the contribution.

This package is actually quite outdated now. It still works but there's a much newer python-ecosys/aiohttp package which has a lot more features than this one (although not basic auth yet...).

Do you have a particular reason to use uaiohttpclient?

If we continue to maintain this package then it should offer something different to python-ecosys/aiohttp. For example this one should be much more light weight.

mirko commented 2 weeks ago

I just picked the first async HTTP client lib I found, verified it working, embedding it into my project - and found out (way too late), it lacks HTTP auth. And instead of searching around and trying out other libs with each havingtheir own quirks and uasynciohttpclient basically working for me. I just hacked it in and created this PR.

dpgeorge commented 2 weeks ago

OK, thanks for the explanation.

I'm happy to accept the changes in this PR, but will make some more specific comments about them.