Index: http/response.py
===================================================================
--- http/response.py	(revision 57)
+++ http/response.py	(working copy)
@@ -111,6 +111,8 @@
         added.
       compress : bool
         should the body of the response be compressed?
+      chunked : bool
+        should the response be Transfer-Encoding chunked
     """
 
     def __init__(self):
@@ -119,6 +121,7 @@
         self.set_compress(False)
         self.set_expires(0)
         self.set_buffered(True)
+        self.set_chunked(False)
         self.headers = {}
         self.cookies = {}
         self.body = None
@@ -140,6 +143,12 @@
     def get_compress(self):
         return self.compress
 
+    def set_chunked(self, value):
+        self.chunked = value
+
+    def get_chunked(self):
+        return self.chunked
+
     def set_buffered(self, value):
         self.buffered = value
 
@@ -349,8 +358,13 @@
             length = self.get_content_length()
             if length is not None:
                 yield ('Content-Length', str(length))
-
-
+            else:
+                # Transfer-Encoding
+                self.set_chunked(True)
+                yield ('Transfer-Encoding', 'chunked')
+                if self.get_compress() and self.get_mime_type() not in _GZIP_EXCLUDE:
+                    yield ("Content-Encoding", "gzip")
+        
     def generate_body_chunks(self):
         """
         Return a sequence of body chunks, encoded using 'charset'.
@@ -360,8 +374,31 @@
         if self.body is None:
             pass
         elif isinstance(self.body, Stream):
-            for chunk in self.body:
-                yield self._encode_chunk(chunk)
+            if self.get_chunked() and self.get_compress() and self.get_mime_type() not in _GZIP_EXCLUDE:
+                co = crc = clen = gz_chunk = None
+                crc = zlib.crc32("")
+                clen = 0
+                co = zlib.compressobj(6, zlib.DEFLATED, -zlib.MAX_WBITS,
+                        zlib.DEF_MEM_LEVEL, 0)
+                yield _GZIP_HEADER
+                for chunk in self.body:
+                    clen += len(chunk)
+                    crc = zlib.crc32(chunk, crc)
+    
+                    gz_chunk = co.compress(self._encode_chunk(chunk))
+                    if not gz_chunk:
+                        continue
+    
+                    yield gz_chunk
+
+                gz_chunk = co.flush()
+                yield gz_chunk
+                end = struct.pack("<ll", crc, clen)
+                yield end
+
+            else:                
+                for chunk in self.body:
+                    yield self._encode_chunk(chunk)
         else:
             yield self.body # already encoded by set_body().
 
@@ -383,15 +420,23 @@
         for name, value in self.generate_headers():
             output.write("%s: %s\r\n" % (name, value))
         output.write("\r\n")
+        
         if flush_output:
             output.flush()
         if not include_body:
             return
         for chunk in self.generate_body_chunks():
+            if self.get_chunked():
+                output.write("%x\r\n" % len(chunk))
             output.write(chunk)
+
             if flush_output:
+                if self.get_chunked():
+                    output.write("\r\n")
                 output.flush()
         if flush_output:
+            if self.get_chunked():
+                output.write("0\r\n\r\n")
             output.flush()
 
 class Stream:
Index: fill/static.qpy
===================================================================
--- fill/static.qpy	(revision 57)
+++ fill/static.qpy	(working copy)
@@ -39,7 +39,7 @@
     """
 
     def __init__(self, path, mime_type=None, encoding=None, cache_time=None,
-                 charset='iso-8859-1'):
+                 charset='iso-8859-1', chunked=False, compress=False):
         """
         If omitted, the MIME type will be guessed, defaulting to text/plain.
 
@@ -55,6 +55,8 @@
         self.encoding = encoding or guess_enc or None
         self.cache_time = cache_time
         self.charset = charset
+        self.chunked = chunked
+        self.compress = compress
 
     def __call__(self):
         try:
@@ -84,8 +86,15 @@
         get_response().set_content_type(self.mime_type, self.charset)
         if self.encoding:
             get_response().set_header("Content-Encoding", self.encoding)
+        
+        size = stat.st_size
+        if self.compress or self.chunked:
+            size = None
+            get_response().set_compress(self.compress)
+            get_response().set_chunked(self.chunked)
+            get_response().set_buffered(False)
 
-        return FileStream(open(self.path, 'rb'), stat.st_size)
+        return FileStream(open(self.path, 'rb'), size)
 
 
 class StaticDirectory(Directory):
@@ -97,7 +106,7 @@
 
     def __init__(self, path, list_directory=False,
                  cache_time=None, index_filenames=None, 
-                 follow_links=False):
+                 follow_links=False, chunked=False, compress=False):
         """(path:string, list_directory:bool,
             cache_time:int,
             index_filenames:[string])
@@ -111,6 +120,11 @@
         Optional parameter 'index_filenames' specifies a list of
         filenames to be used as index files in the directory. First
         file found searching left to right is returned.
+        
+        Optional parameter 'chunked' turns on Transfer-Encoding chunked.
+        
+        Optional parameter 'compress' attempts to compress the file, this 
+        implies chunked=True.
         """
         if not os.path.isabs(path):
             raise ValueError, "Path %r is not absolute" % path
@@ -119,6 +133,8 @@
         self.cache_time = cache_time
         self.index_filenames = index_filenames
         self.follow_links = follow_links
+        self.chunked = chunked
+        self.compress = compress
 
     def generate_visible_names(self):
         files = os.listdir(self.path)
@@ -186,5 +202,5 @@
                 index_filenames=self.index_filenames,
                 follow_links=self.follow_links)
         elif os.path.isfile(item_filepath):
-            return self.file_class(item_filepath, cache_time=self.cache_time)
+            return self.file_class(item_filepath, cache_time=self.cache_time, chunked=self.chunked, compress=self.compress)
         return None
