Skip to content

Commit ab03745

Browse files
tjfontaineisaacs
authored andcommitted
http_parser: expose pause/resume method for parser
1 parent 9901415 commit ab03745

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/node_http_parser.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ class Parser : public WeakObject {
482482
}
483483

484484

485+
template <bool should_pause>
486+
static void Pause(const FunctionCallbackInfo<Value>& args) {
487+
Environment* env = Environment::GetCurrent(args.GetIsolate());
488+
HandleScope handle_scope(args.GetIsolate());
489+
Parser* parser = WeakObject::Unwrap<Parser>(args.This());
490+
// Should always be called from the same context.
491+
assert(env == parser->env());
492+
http_parser_pause(&parser->parser_, should_pause);
493+
}
494+
495+
485496
private:
486497

487498
Local<Array> CreateHeaders() {
@@ -588,6 +599,8 @@ void InitHttpParser(Handle<Object> target,
588599
NODE_SET_PROTOTYPE_METHOD(t, "execute", Parser::Execute);
589600
NODE_SET_PROTOTYPE_METHOD(t, "finish", Parser::Finish);
590601
NODE_SET_PROTOTYPE_METHOD(t, "reinitialize", Parser::Reinitialize);
602+
NODE_SET_PROTOTYPE_METHOD(t, "pause", Parser::Pause<true>);
603+
NODE_SET_PROTOTYPE_METHOD(t, "resume", Parser::Pause<false>);
591604

592605
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "HTTPParser"),
593606
t->GetFunction());

0 commit comments

Comments
 (0)