Comparison

util/httpstream.lua @ 3566:75d287daad16

util.httpstream: Added support for an options callback, to allow passing per-message options to the parser.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 06 Nov 2010 01:54:58 +0500
parent 3565:e2cc09e83a3e
child 3567:94828fb2dab8
comparison
equal deleted inserted replaced
3565:e2cc09e83a3e 3566:75d287daad16
5 local deadroutine = coroutine.create(function() end); 5 local deadroutine = coroutine.create(function() end);
6 coroutine.resume(deadroutine); 6 coroutine.resume(deadroutine);
7 7
8 module("httpstream") 8 module("httpstream")
9 9
10 local function parser(success_cb, parser_type) 10 local function parser(success_cb, parser_type, options_cb)
11 local data = coroutine.yield(); 11 local data = coroutine.yield();
12 local function readline() 12 local function readline()
13 local pos = data:find("\r\n", nil, true); 13 local pos = data:find("\r\n", nil, true);
14 while not pos do 14 while not pos do
15 data = data..coroutine.yield(); 15 data = data..coroutine.yield();
91 }); 91 });
92 end 92 end
93 else coroutine.yield("unknown-parser-type"); end 93 else coroutine.yield("unknown-parser-type"); end
94 end 94 end
95 95
96 function new(success_cb, error_cb, parser_type) 96 function new(success_cb, error_cb, parser_type, options_cb)
97 local co = coroutine.create(parser); 97 local co = coroutine.create(parser);
98 coroutine.resume(co, success_cb, parser_type) 98 coroutine.resume(co, success_cb, parser_type, options_cb)
99 return { 99 return {
100 feed = function(self, data) 100 feed = function(self, data)
101 if not data then 101 if not data then
102 if parser_type == "client" then coroutine.resume(co, ""); end 102 if parser_type == "client" then coroutine.resume(co, ""); end
103 co = deadroutine; 103 co = deadroutine;