Aug 29, 2007

tracd does not accept folded http header

I found that tracd does not work in some cases, specifically when the http header is folded because of its longness. To solve this problem, I modified /usr/lib/python2.4/site-packages/trac/web/ as following.
  1. Make unfold_header function.
    def unfold_header(self):
        lineno = 1
        while lineno < len(self.headers.headers):
            header = self.headers.headers[lineno]
            if header.startswith(' ') or header.startswith('\t'):
                self.headers.headers[lineno - 1] += header
                lineno = lineno + 1
  2. Call this function from setup_environ function in WSGIRequestHandler class.
    length = self.headers.getheader('content-length')
    if length:
        environ['CONTENT_LENGTH'] = length
    # insert this line here.
    for name, value in [header.split(':', 1) for header
                        in self.headers.headers]:
This was my first time to program in Python, so there might be some problems. But this modified tracd is working for now.

No comments: