Created
October 2, 2011 13:24
Revisions
-
nickstenning revised this gist
Oct 2, 2011 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,10 @@ import time # This just works, but if we're being really good we should probably set # protocol_version = HTTP/1.1 # in the server:main section of the config file. def chunky(iterable): def _chunkify(chunk): return '%s\r\n%s\r\n' % (hex(len(chunk))[2:], chunk) @@ -20,6 +24,7 @@ def _counter(n): yield '%d\n' % i time.sleep(1) response.headers['Content-Type'] = 'text/plain' response.headers['Transfer-Encoding'] = 'chunked' return chunky(_counter(int(num))) -
nickstenning created this gist
Oct 2, 2011 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ from streamapp.lib.base import BaseController from pylons import response import time def chunky(iterable): def _chunkify(chunk): return '%s\r\n%s\r\n' % (hex(len(chunk))[2:], chunk) for chunk in iterable: yield _chunkify(chunk) yield '0\r\n\r\n' class StreamController(BaseController): def count(self, num): def _counter(n): for i in xrange(n): yield '%d\n' % i time.sleep(1) response.headers['Transfer-Encoding'] = 'chunked' return chunky(_counter(int(num)))