ext/kcar/kcar.c in kcar-0.3.1 vs ext/kcar/kcar.c in kcar-0.4.0

- old
+ new

@@ -1366,10 +1366,28 @@ return Qnil; } /** + * call-seq: + * parser.body_bytes_left = Integer + * + * Sets the number of bytes left to download for HTTP responses + * with "Content-Length". This raises RuntimeError for chunked + * responses. + */ +static VALUE body_bytes_left_set(VALUE self, VALUE bytes) +{ + struct http_parser *hp = data_get(self); + + if (HP_FL_TEST(hp, CHUNKED)) + rb_raise(rb_eRuntimeError, "body_bytes_left= is not for chunked bodies"); + hp->len.content = NUM2OFFT(bytes); + return bytes; +} + +/** * Document-method: chunked * call-seq: * parser.chunked? => true or false * * This is used to detect if a response uses chunked Transfer-Encoding or not. @@ -1539,9 +1557,10 @@ rb_define_method(cParser, "reset", initialize, 0); rb_define_method(cParser, "headers", headers, 2); rb_define_method(cParser, "trailers", headers, 2); rb_define_method(cParser, "filter_body", filter_body, 2); rb_define_method(cParser, "body_bytes_left", body_bytes_left, 0); + rb_define_method(cParser, "body_bytes_left=", body_bytes_left_set, 1); rb_define_method(cParser, "body_eof?", body_eof, 0); rb_define_method(cParser, "keepalive?", keepalive, 0); rb_define_method(cParser, "chunked?", chunked, 0); /*