Added Secured flag for HttpRequest

This commit is contained in:
斟酌 鵬兄 2016-03-22 01:16:24 +08:00
parent 7ce7dec57c
commit 3ec995e193

View File

@ -37,6 +37,8 @@ class HttpRequest extends EventEmitter
this.Headers = Headers || { this.Headers = Headers || {
"User-Agent": "BotanSS HttpRequest" "User-Agent": "BotanSS HttpRequest"
}; };
this.Secured = false;
} }
SetUrl( Url ) SetUrl( Url )
@ -52,6 +54,7 @@ class HttpRequest extends EventEmitter
case "https://": case "https://":
Url = Url.substr( 8 ); Url = Url.substr( 8 );
this.Port = 443; this.Port = 443;
this.Secured = true;
break; break;
} }
@ -80,7 +83,7 @@ class HttpRequest extends EventEmitter
{ {
if( !this.Hostname ) throw new Error( "Url not set" ); if( !this.Hostname ) throw new Error( "Url not set" );
var req = ( this.Port == 80 ? http : https ) var req = ( this.Secured ? https : http )
.request( this.Options, this.OnResponseReceived.bind( this ) ); .request( this.Options, this.OnResponseReceived.bind( this ) );
req.end( this.RawPostData ); req.end( this.RawPostData );
} }