◐ Shell
clean mode source ↗

gh-69152: add method get_proxy_response_headers to HTTPConnection class by nametkin · Pull Request #104248 · python/cpython

Sorry for being late for the review, but I would like to note that get_proxy_response_headers now is not consistent in its return type. If there are headers, it returns HTTPMessage class (which has this mro: (<class 'http.client.HTTPMessage'>, <class 'email.message.Message'>, <class 'object'>)), but if there are no headers it returns {}. Why?

I think that the source of this confusion is that email.message.Message behaves like a Mapping, but I still think that we should change the default value to None before it is too late.

This way we can say that this method returns Optional[HTTPMessage] and not HTTPMessage | dict[str, str] (or Mapping[str, str], which will erase a lot of useful methods).

I will open a new PR for this.