Simplify the code of HttpRequest
This commit is contained in:
parent
4e200c88a9
commit
a83d3d9469
@ -7,8 +7,9 @@ var https = require( "https" );
|
|||||||
|
|
||||||
class HttpRequestCompleteEventArgs
|
class HttpRequestCompleteEventArgs
|
||||||
{
|
{
|
||||||
constructor( ResponseData )
|
constructor( statusCode, ResponseData )
|
||||||
{
|
{
|
||||||
|
this.statusCode = statusCode;
|
||||||
this.Data = ResponseData;
|
this.Data = ResponseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,20 +92,18 @@ class HttpRequest extends EventEmitter
|
|||||||
|
|
||||||
OnResponseReceived( Response )
|
OnResponseReceived( Response )
|
||||||
{
|
{
|
||||||
this.ResponseData = new Buffer( 0 );
|
var _self = this;
|
||||||
Response.addListener( "data", this.OnResponseData.bind( this ) );
|
var ResponseData = new Buffer( 0 );
|
||||||
Response.addListener( "end", this.OnResponseComplete.bind( this ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
OnResponseComplete()
|
Response.addListener( "data",
|
||||||
{
|
Data => ResponseData = Buffer.concat([ ResponseData, Data ])
|
||||||
this.emit( "RequestComplete"
|
);
|
||||||
, this, new HttpRequestCompleteEventArgs( this.ResponseData ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
OnResponseData( Data )
|
Response.addListener( "end", () => {
|
||||||
{
|
_self.emit( "RequestComplete"
|
||||||
this.ResponseData = Buffer.concat([ this.ResponseData, Data ]);
|
, this, new HttpRequestCompleteEventArgs( Response.statusCode, ResponseData )
|
||||||
|
);
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user