← index #844PR #74
Off-topic · high · value 0.093
QUERY · ISSUE

urequests still using HTTP/1.0

openby linusoftopened 2024-04-11updated 2024-05-06

The urequests module is still using HTTP/1.0 for HTTP requests:

line 39 in micropython-lib/micropython/urllib.urequest/urllib/urequest.py on the master branch:

s.write(b" HTTP/1.0\r\nHost: ")

Since a host header is included, can this be updated to use HTTP/1.1 or even HTTP/2.0?

Some sites (e.g. mongodb) are now responding with '426 Update Required' for HTTP/1.0 requests.

Thanks

3 comments
th4ruka · 2024-05-05

Hey! I also think it is better to update the header in line 39 of micropython-lib/micropython/urllib.urequest/urllib/urequest.py as,

- s.write(b" HTTP/1.0\r\nHost: ")
+ s.write(b" HTTP/2.0\r\nHost: ") 

As I know, most major web servers and CDNs provide backward compatibility. Therefore there will be no harm by updating it.

sosi-deadeye · 2024-05-05

HTTP/2 is a binary protocol and uses HPACK for header compression. Changing this, require additional code to handle the protocol and header compression.

I also think the change to HTTP/1.1 may require some additional code, to handle the different connection types : close, keep-alive.

In addition, there are different Transfer-Endocings.

mattytrentini · 2024-05-06

It would be good to merge back some of the changes from the CircuitPython requests library (they've updated it since originally starting with the MicroPython implementation). In it, they respond with v1.1, though I'm not sure it 100% conforms to spec...

https://github.com/adafruit/Adafruit_CircuitPython_Requests/blob/main/adafruit_requests.py

CANDIDATE · PULL REQUEST

urequests: support ports other than default

closedby garybakeopened 2016-05-19updated 2016-05-21

Sourced from https://github.com/kennethreitz/requests/blob/190cddd4ae7d649ea6d85d062fd6e4a69d0cf417/requests/packages/urllib3/util/url.py#L179

4 comments
garybake · 2016-05-20

Thank you for the comments.
For my own curiosity - the removal of theif ':' in hostname: was this due to efficiency with micropython or just a more pythonic way of doing it?

pfalcon · 2016-05-20

Please avoid this if, and having both "host" and "hostname" vars.

I'm sorry for formulating it in such confusing way. I meant "avoid else". I.e. instead of:

if ...:
    var = expr
else:
    var = const

preferrable to use:

var = const
if ...:
    var = expr

This will make code a tiny bit shorter and tiny bit more efficient.

garybake · 2016-05-20

Gotcha - I've updated the file

pfalcon · 2016-05-21

Merged with fixes, thanks.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied