New submission from Ent: 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. ---------- components: Library (Lib) files: simplehttp.patch keywords: patch messages: 234165 nosy: last-ent priority: normal severity: normal status: open title: SimpleHTTPRequestHandler refactor for more extensible usage. type: enhancement versions: Python 3.4 Added file: http://bugs.python.org/file37736/simplehttp.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23255> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com