Matt Eaton <agnostic...@gmail.com> added the comment:

Oliver,

A possible option that would work for both the client side caching and the 
server would be to pass back a Cache-Control header with a max-age attached 
when the 301 is returned.

I am thinking something like this:

if os.path.isdir(path):
    parts = urllib.parse.urlsplit(self.path)
    if not parts.path.endswith('/'):
        # redirect browser - doing basically what apache does
        self.send_response(HTTPStatus.MOVED_PERMANENTLY)
        new_parts = (parts[0], parts[1], parts[2] + '/',
                     parts[3], parts[4])
        new_url = urllib.parse.urlunsplit(new_parts)
        self.send_header("Location", new_url)
        self.send_header("Cache-Control", "max-age=600")
        self.end_headers()
        return None
    for index in "index.html", "index.htm":
        index = os.path.join(path, index)
        if os.path.exists(index):
            path = index
            break


Possibly we could even provide some way for the max age to be variable.
Thoughts?

----------
nosy: +agnosticdev

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33181>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to