If this is not the appropriate place for this type of proposal please let me know.
The modules http.client and http.server both do a wonderful job when implementing HTTP clients and servers, respectively. However, occasionally there may be a need to create and parse HTTP messages themselves without needing to implement a client or server. While http.client and http.server clearly have solved this problem for its own uses, there is little to no public API exposed to a user wishing to do the same. For instance, the documentation for http.client.HTTPMessage 1 simply states that it extends from email.message.Message in order to parse the messages.
While this need may admittedly be a niche one, it is a shame that one cannot simply use the functionality already implemented for http.client and http.server for this purpose. Therefore, I am proposing this module be improved such that the creation and parsing of HTTP messages be "pulled out of" the existing code into HTTPRequest and HTTPResponse classes with a public API for this purpose. The exact API is subject to change of course, but it could work like:
r = http.client.HTTPRequest("POST", "/foo", "Hello world!") r.method 'POST' r.body 'Hello world!' print(r) POST /foo HTTP/1.1 Content-Length: 12
If this idea is not completely a bad one, I am very interested in discussing in further detail how I (or perhaps someone else) could begin to implement these changes.
Thank you for reading.
On Mon, Apr 16, 2018 at 11:21 PM, Derek Maciel firstname.lastname@example.org wrote:
The modules http.client and http.server both do a wonderful job when implementing HTTP clients and servers, respectively. However, occasionally there may be a need to create and parse HTTP messages themselves without needing to implement a client or server.
The way http.client/http.server are written, the code for creating and parsing messages is very tangled up with the code for sending and receiving data, so this wouldn't be easy to do without rewriting them from scratch. But would you accept a third-party package? https://h11.readthedocs.io
-- Nathaniel J. Smith -- https://vorpus.org