From c297fde2000dcc8bdf7cb9f912fb2ea07be1c282 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 13 Jun 2011 23:42:54 +0000 Subject: http: dechunk! method to enter dechunk mode This allows one to enter the dechunker without parsing HTTP headers beforehand. Since we skipped header parsing, trailer parsing is not supported since we don't know what trailers might be (to our knowledge, nobody uses trailers anyways) --- ext/unicorn_http/unicorn_http.rl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ext') diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 106cc6b..f799337 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -629,6 +629,34 @@ static VALUE HttpParser_clear(VALUE self) return self; } +/** + * call-seq: + * parser.chunk_ready! => parser + * + * Resets the parser to a state suitable for dechunking response bodies + * + */ +static VALUE HttpParser_dechunk_bang(VALUE self) +{ + struct http_parser *hp = data_get(self); + + http_parser_init(hp); + + /* + * we don't care about trailers in dechunk-only mode, + * but if we did we'd set UH_FL_HASTRAILER and clear hp->env + */ + if (0) { + rb_funcall(hp->env, id_clear, 0); + hp->flags = UH_FL_HASTRAILER; + } + + hp->flags |= UH_FL_HASBODY | UH_FL_INBODY | UH_FL_CHUNKED; + hp->cs = http_parser_en_ChunkedBody; + + return self; +} + /** * call-seq: * parser.reset => nil @@ -954,6 +982,7 @@ void Init_unicorn_http(void) rb_define_method(cHttpParser, "initialize", HttpParser_init, 0); rb_define_method(cHttpParser, "clear", HttpParser_clear, 0); rb_define_method(cHttpParser, "reset", HttpParser_reset, 0); + rb_define_method(cHttpParser, "dechunk!", HttpParser_dechunk_bang, 0); rb_define_method(cHttpParser, "parse", HttpParser_parse, 0); rb_define_method(cHttpParser, "add_parse", HttpParser_add_parse, 1); rb_define_method(cHttpParser, "headers", HttpParser_headers, 2); -- cgit v1.2.3-24-ge0c7