I would like to extend kid.server to use chunked transfer (HTTP/1.1),
so that slow to be generated results can be incrementally built by the
web browser. [This is for use as a simple desktop data server]. I
hacked kid.server to implement the protocol as described in RFC 2616
<http://rfc.dotsrc.org/rfc/rfc2616.html> (Section 3.6.1 Chunked
Transfer Coding) and verified that it worked with Mozilla FireFox
1.5.0.1. Further testing, however, revealed that my hack didn't work
in MS Internet Explorer 6.0. IE doesn't seem to be reading the
response as chunked, leaving the chunk-size and extra CRLFs in the
message body. Can someone with more HTTP protocol experience spot my
error? Do I need an additional header to notify IE that the server is
sending chunked? I've included the hack and test template below.
Thanks!

lx

=== diff server.py  myserver.py ===

71a72,82
> class ChunkWriter(object):
>     def __init__(self, file):
>         self.file = file
>     def __del__(self):
>         self.close()
>     def write(self, data):
>         self.file.write(hex(len(data))[2:] + '\r\n')
>         self.file.write(data + '\r\n')
>     def close(self):
>         self.file.write('0\r\n')
>
73a85,87
>     cache = 0
>     chunked = True
>
183,187c197
<             template_module = load_template(scriptfile, cache=1)
<             template = template_module.Template(
<                 request=self, environ=env,
<                 FieldStorage=FieldStorage(self.rfile, environ=env))
<             s = str(template)
---
>             template_module = load_template(scriptfile, cache=self.cache)
189,191c199,213
<             self.send_header("Content-Length", str(len(s)))
<             self.end_headers()
<             self.wfile.write(s)
---
>             if self.chunked and self.request_version == 'HTTP/1.1':
>                 self.send_header("Transfer-Encoding", "chunked")
>                 self.end_headers()
>                 template = template_module.Template(request=self, environ=env,
>                     FieldStorage=FieldStorage(self.rfile, environ=env))
>                 template.write(ChunkWriter(self.wfile))
>             else:
>                 template = template_module.Template(
>                     request=self, environ=env,
>                     FieldStorage=FieldStorage(self.rfile, environ=env))
>                 s = str(template)
>                 self.send_header("Content-Length", str(len(s)))
>                 self.end_headers()
>                 self.wfile.write(s)
>

=== testchunked.kid ===

<?xml version='1.0' encoding='utf-8'?>
<?python import time?>
<html xmlns:py="http://purl.org/kid/ns#";>
    <head>
        <title>Test Chunked Transfer</title>
    </head>
    <body>
        <table>
            <colgroup span="2" width="372">
                <col width="72"/>
                <col width="300"/>
            </colgroup>
            <tr>
                <td>Iteration</td><td>Time</td>
            </tr>
            <tr py:for="i in range(10)">
                <?python
time.sleep(1)?><td>${i+1}</td><td>${time.asctime()}</td>
            </tr>
        </table>
    </body>
</html>


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
kid-template-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kid-template-discuss

Reply via email to