durusmail: quixote-users: Overlaying a static directory
Overlaying a static directory
2005-04-11
2005-04-12
2005-04-12
2005-04-12
2005-04-13
2005-04-13
2005-04-14
2005-04-14
2005-04-14
2005-04-14
2005-04-14
2005-04-14
2005-04-14
2005-04-14
2005-04-14
2005-04-14
David Binger (3 parts)
2005-04-14
2005-04-14
2005-04-13
2005-04-14
2005-04-14
2005-04-13
SCGI util.
2005-04-12
2005-04-13
2005-04-13
2005-04-13
2005-04-13
Overlaying a static directory
mso@oz.net
2005-04-14
David Binger wrote:
> Another interesting test would be to comment out lines in
> StaticFile that set headers.

Commenting out this line gets rid of the internal server error:

    response.set_header('Last-Modified', last_modified)

However, the images/stylesheet still come and go.

This very conservative method gets rid of the image problem sometimes but
not always.


    def __call__(self):
        if not self.follow_symlinks and os.path.islink(self.path):
            raise errors.TraversalError(private_msg="Path %r is a symlink"
                                        % self.path)
        #stat = os.stat(self.path)
        #last_modified = formatdate(stat.st_mtime)
        #request = quixote.get_request()
        response = quixote.get_response()
        #if last_modified == request.get_header('If-Modified-Since'):
        #    # handle exact match of If-Modified-Since header
        #    response.set_status(304)
        #    return ''

        # Set the Content-Type for the response and return the file's
contents.
        response.set_content_type(self.mime_type)
        #if self.encoding:
        #    response.set_header("Content-Encoding", self.encoding)

        #response.set_header('Last-Modified', last_modified)

        #if self.cache_time is None:
        #    response.set_expires(None) # don't set the Expires header
        #else:
        #    # explicitly allow client to cache page by setting the Expires
        #    # header, this is even more efficient than the using
        #    # Last-Modified/If-Modified-Since since the browser does not
need
        #    # to contact the server
        #    response.set_expires(seconds=self.cache_time)

        #return FileStream(open(self.path, 'rb'), stat.st_size)
        f = open(self.path, 'rb')
        content = f.read()
        f.close()
        return content

I have to set the content type, otherwise the stylesheet goes out the
window completely.

Also, with the standard SessionManager that uses a dictionary, if I reload
a static page a couple of times, it forgets I'm logged in (session.user is
None).  Because my application traps this and redirects to the login page,
I have to keep re-logging in.  I had to comment the redirect code to test
the static pages.  I've been using DirMapping but switched to the standard
SessionManager yesterday to rule out file problems.  I just switched back
to DirMapping and the problem seems to be gone.  It's not losing the
entire session, just the User object.  If I restart the server, I get the
usual "session expired" message, but that's to be expected.


reply