Message234165
Use of http.server.BaseHTTPRequestHandler for exploratory or simple usage, SimpleHTTPRequestHandler provides a good platform to start on. However, the current code in SimpleHTTPRequestHandler's send_head is tightly coupled together as a single unit.
This patch aims to break send_head down into composable parts so that any developer can subclass SimpleHTTPRequestHandler to create one's own HTTPRequestHandler class with their own custom behaviour without having to rewrite a lot of repeated code.
For example consider a developer wanting to address two usecases
* Use SimpleHTTPRequestHandler, but use index.html from a different directory.
* For certain GET urls, call on a specific function to response.
* Use custom html page instead of index.html
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path =='/':
f = self.home_head()
elif self.path in self.custom_paths:
f = self.special_head()
else:
f = self.send_head()
# ...
# Standard Code
As a result of the patch, in above scenario instead of copy-pasting logic for browser redirection, getting object for file or directory and, applying headers upon success; Developer can use methods redirect_browser, get_dir_or_html_dir_path and, apply_headers to reduce the code.
Basically, applying DRY principle.
Note: Since this is but refactoring of existing code without any new functionality being added, no test cases are provided. |
|
Date |
User |
Action |
Args |
2015-01-17 13:51:58 | last-ent | set | recipients:
+ last-ent |
2015-01-17 13:51:58 | last-ent | set | messageid: <1421502718.52.0.546532418197.issue23255@psf.upfronthosting.co.za> |
2015-01-17 13:51:58 | last-ent | link | issue23255 messages |
2015-01-17 13:51:57 | last-ent | create | |
|