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 last-ent
Recipients last-ent
Date 2015-01-17.13:51:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1421502718.52.0.546532418197.issue23255@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-01-17 13:51:58last-entsetrecipients: + last-ent
2015-01-17 13:51:58last-entsetmessageid: <1421502718.52.0.546532418197.issue23255@psf.upfronthosting.co.za>
2015-01-17 13:51:58last-entlinkissue23255 messages
2015-01-17 13:51:57last-entcreate