1+ process . env [ "NODE_TLS_REJECT_UNAUTHORIZED" ] = "0" ;
2+
13import { ClientRequest , RequestOptions , request as httpRequest } from "http" ;
4+ import { request as httpsRequest } from "https" ;
25import { join } from "path" ;
36import { deepEqual } from "assert" ;
47
@@ -9,23 +12,24 @@ import { TColor } from "../../common.types";
912type THeaders = { [ key : string ] : string } ;
1013
1114type TConfiguration = RequestOptions & {
15+ https ?: boolean ;
1216 pathRoot ?: string ;
1317} ;
1418
1519interface IResponse {
16- status ?: number ;
17- headers ?: THeaders ;
1820 body ?: unknown ;
21+ headers ?: THeaders ;
22+ status ?: number ;
1923}
2024
2125export class HTTPTest extends Test < IResponse > {
2226 public static readonly suiteTitle : string = "HTTP" ;
2327 public static readonly suiteColor : TColor = [ 177 , 66 , 179 ] ;
2428
2529 private static configuration : TConfiguration = {
26- method : "GET" ,
27- protocol : "http:" ,
2830 hostname : "localhost" ,
31+ https : false ,
32+ method : "GET" ,
2933 port : 80
3034 } ;
3135
@@ -35,7 +39,7 @@ export class HTTPTest extends Test<IResponse> {
3539 ...configuration
3640 } ;
3741 }
38-
42+
3943 protected evalActualExpression (
4044 path : string ,
4145 options : TConfiguration & {
@@ -44,15 +48,16 @@ export class HTTPTest extends Test<IResponse> {
4448 ) : Promise < IResponse > {
4549 // TODO: Overloads
4650 return new Promise ( ( resolve , reject ) => {
47- const reqOptions : RequestOptions = {
51+ const reqOptions : TConfiguration & RequestOptions = {
4852 ...HTTPTest . configuration ,
4953
5054 path : encodeURI ( join ( HTTPTest . configuration . pathRoot ?? "" , path ) ) ,
5155
5256 ...options
5357 } ;
58+ reqOptions . protocol = `http${ reqOptions . https ? "s" : "" } :` ;
5459
55- const req : ClientRequest = httpRequest ( reqOptions , ( res ) => {
60+ const req : ClientRequest = ( reqOptions . https ? httpsRequest : httpRequest ) ( reqOptions , ( res ) => {
5661 const body : Buffer [ ] = [ ] ;
5762 res . on ( "data" , ( chunk : Buffer ) => {
5863 body . push ( chunk ) ;
0 commit comments