This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maggyero
Recipients eric.araujo, maggyero
Date 2022-01-23.18:29:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642962573.68.0.0801390367745.issue46436@roundup.psfhosted.org>
In-reply-to
Content
Thanks for mentioning this issue @merwok.

As you pointed out, function `test` in module [`http.server`](https://github.com/python/cpython/blob/main/Lib/http/server.py) expects a real request handler class argument (`SimpleHTTPRequestHandler` or `CGIHTTPRequestHandler`), not a partial object `partial(SimpleHTTPRequestHandler, directory=args.directory)` or `partial(CGIHTTPRequestHandler, directory=args.directory)`, so that the assignment of `protocol_version` class attribute in test is not ignored.

The partial object in the `if __name__ == '__main__'` branch of module `http.server` was introduced in the first place to pass the directory argument to the request handler class’s `__init__` method called in method `BaseServer.finish_request` of module [`socketserver`](https://github.com/python/cpython/blob/main/Lib/socketserver.py):

    def finish_request(self, request, client_address):
        """Finish one request by instantiating RequestHandlerClass."""
        self.RequestHandlerClass(request, client_address, self)

But `BaseServer.finish_request` is a factory method of `BaseServer` (the abstract creator) so it is *designed* to be overridden in subclasses to customize the instantiation of the request handler class `BaseRequestHandler` (the abstract product). So the proper way to instantiate `SimpleHTTPRequestHandler` and `CGIHTTPRequestHandler` with the `directory` argument is to override `BaseServer.finish_request`.

I have just updated my PR to implement this. It fixes both [#46285](https://bugs.python.org/issue46285) and [#46436](https://bugs.python.org/issue46436).
History
Date User Action Args
2022-01-23 18:29:33maggyerosetrecipients: + maggyero, eric.araujo
2022-01-23 18:29:33maggyerosetmessageid: <1642962573.68.0.0801390367745.issue46436@roundup.psfhosted.org>
2022-01-23 18:29:33maggyerolinkissue46436 messages
2022-01-23 18:29:33maggyerocreate