@ -2,8 +2,8 @@
# include "node_buffer.h"
# include "node_buffer.h"
# include "node_http_parser.h"
# include "node_http_parser.h"
# include "base-object .h"
# include "async-wrap .h"
# include "base-object -inl.h"
# include "async-wrap -inl.h"
# include "env.h"
# include "env.h"
# include "env-inl.h"
# include "env-inl.h"
# include "stream_base.h"
# include "stream_base.h"
@ -147,10 +147,10 @@ struct StringPtr {
} ;
} ;
class Parser : public BaseObject {
class Parser : public AsyncWrap {
public :
public :
Parser ( Environment * env , Local < Object > wrap , enum http_parser_type type )
Parser ( Environment * env , Local < Object > wrap , enum http_parser_type type )
: BaseObject ( env , wrap ) ,
: AsyncWrap ( env , wrap , AsyncWrap : : PROVIDER_HTTPPARSER ) ,
current_buffer_len_ ( 0 ) ,
current_buffer_len_ ( 0 ) ,
current_buffer_data_ ( nullptr ) {
current_buffer_data_ ( nullptr ) {
Wrap ( object ( ) , this ) ;
Wrap ( object ( ) , this ) ;
@ -164,6 +164,11 @@ class Parser : public BaseObject {
}
}
size_t self_size ( ) const override {
return sizeof ( * this ) ;
}
HTTP_CB ( on_message_begin ) {
HTTP_CB ( on_message_begin ) {
num_fields_ = num_values_ = 0 ;
num_fields_ = num_values_ = 0 ;
url_ . Reset ( ) ;
url_ . Reset ( ) ;
@ -285,8 +290,10 @@ class Parser : public BaseObject {
argv [ A_UPGRADE ] = Boolean : : New ( env ( ) - > isolate ( ) , parser_ . upgrade ) ;
argv [ A_UPGRADE ] = Boolean : : New ( env ( ) - > isolate ( ) , parser_ . upgrade ) ;
Environment : : AsyncCallbackScope callback_scope ( env ( ) ) ;
Local < Value > head_response =
Local < Value > head_response =
cb . As < Function > ( ) - > Call ( obj , ARRAY_SIZE ( argv ) , argv ) ;
MakeCallback ( cb . As < Function > ( ) , ARRAY_SIZE ( argv ) , argv ) ;
if ( head_response . IsEmpty ( ) ) {
if ( head_response . IsEmpty ( ) ) {
got_exception_ = true ;
got_exception_ = true ;
@ -321,7 +328,7 @@ class Parser : public BaseObject {
Integer : : NewFromUnsigned ( env ( ) - > isolate ( ) , length )
Integer : : NewFromUnsigned ( env ( ) - > isolate ( ) , length )
} ;
} ;
Local < Value > r = cb . As < Function > ( ) - > Call ( obj , ARRAY_SIZE ( argv ) , argv ) ;
Local < Value > r = MakeCallback ( cb . As < Function > ( ) , ARRAY_SIZE ( argv ) , argv ) ;
if ( r . IsEmpty ( ) ) {
if ( r . IsEmpty ( ) ) {
got_exception_ = true ;
got_exception_ = true ;
@ -344,7 +351,9 @@ class Parser : public BaseObject {
if ( ! cb - > IsFunction ( ) )
if ( ! cb - > IsFunction ( ) )
return 0 ;
return 0 ;
Local < Value > r = cb . As < Function > ( ) - > Call ( obj , 0 , nullptr ) ;
Environment : : AsyncCallbackScope callback_scope ( env ( ) ) ;
Local < Value > r = MakeCallback ( cb . As < Function > ( ) , 0 , nullptr ) ;
if ( r . IsEmpty ( ) ) {
if ( r . IsEmpty ( ) ) {
got_exception_ = true ;
got_exception_ = true ;
@ -584,7 +593,7 @@ class Parser : public BaseObject {
parser - > current_buffer_len_ = nread ;
parser - > current_buffer_len_ = nread ;
parser - > current_buffer_data_ = buf - > base ;
parser - > current_buffer_data_ = buf - > base ;
cb . As < Function > ( ) - > Call ( obj , 1 , & ret ) ;
parser - > MakeCallback ( cb . As < Function > ( ) , 1 , & ret ) ;
parser - > current_buffer_len_ = 0 ;
parser - > current_buffer_len_ = 0 ;
parser - > current_buffer_data_ = nullptr ;
parser - > current_buffer_data_ = nullptr ;
@ -671,7 +680,7 @@ class Parser : public BaseObject {
url_ . ToString ( env ( ) )
url_ . ToString ( env ( ) )
} ;
} ;
Local < Value > r = cb . As < Function > ( ) - > Call ( obj , ARRAY_SIZE ( argv ) , argv ) ;
Local < Value > r = MakeCallback ( cb . As < Function > ( ) , ARRAY_SIZE ( argv ) , argv ) ;
if ( r . IsEmpty ( ) )
if ( r . IsEmpty ( ) )
got_exception_ = true ;
got_exception_ = true ;