22 * Command Line Manager to parse the command line arguments
33 * and set the necessary fields in RdGlobalConfig.
44 */
5-
65var constants = require ( '../config/constants' ) ;
6+
77var RdGlobalConfig = constants . RdGlobalConfig ;
88
99var CommandLineManager = {
@@ -13,21 +13,25 @@ var CommandLineManager = {
1313 + "\n"
1414 + "Usage: RequestsDebugger [ARGUMENTS]\n\n"
1515 + "ARGUMENTS:\n"
16- + " --port <port> : Port on which the Requests Debugger Tool's Proxy will run\n"
17- + " Default: " + RdGlobalConfig . RD_HANDLER_PORT + "\n"
18- + " --proxy-host <hostname> : Hostname of the Upstream Proxy\n"
19- + " --proxy-port <port> : Port of the Upstream Proxy. Default: " + constants . DEFAULT_PROXY_PORT + " (if hostname is provided)\n"
20- + " --proxy-user <username> : Username for auth of the Upstream Proxy\n"
21- + " --proxy-pass <password> : Password for auth of the Upstream Proxy\n"
22- + " --retry-delay <milliseconds> : Delay for the retry of a failed request. Default: " + RdGlobalConfig . RETRY_DELAY + "ms\n"
23- + " --request-timeout <milliseconds> : Hard timeout for the requests being fired by the tool before receiving any response\n"
24- + " Default: " + RdGlobalConfig . CLIENT_REQ_TIMEOUT + "ms\n"
25- + " --logs-path <relative/absolute path> : Directory where the '" + constants . LOGS_FOLDER + "' folder will be created\n"
26- + " for storing logs. Default: Current Working Directory\n"
27- + " --del-logs : Deletes any existing logs from the " + constants . LOGS_FOLDER + "/ directory and initializes\n"
28- + " new files for logging\n"
29- + " --help : Help for Requests Debugger Tool\n"
30- + " --version : Version of the Requests Debugger Tool\n" ;
16+ + " --proxy-port <port> : Port on which the Requests Debugger Tool's Proxy will run\n"
17+ + " Default: " + RdGlobalConfig . RD_HANDLER_PROXY_PORT + "\n"
18+ + " --reverse-proxy-port <port> : Port on which the Requests Debugger Tool's Reverse Proxy will run\n"
19+ + " Default: " + RdGlobalConfig . RD_HANDLER_REVERSE_PROXY_PORT + "\n"
20+ + " --scheme <https/http> : Scheme for requests to browserstack.\n"
21+ + " Default: " + RdGlobalConfig . SCHEME + "\n"
22+ + " --proxy-host <hostname> : Hostname of the Upstream Proxy\n"
23+ + " --proxy-port <port> : Port of the Upstream Proxy. Default: " + constants . DEFAULT_PROXY_PORT + " (if hostname is provided)\n"
24+ + " --proxy-user <username> : Username for auth of the Upstream Proxy\n"
25+ + " --proxy-pass <password> : Password for auth of the Upstream Proxy\n"
26+ + " --retry-delay <milliseconds> : Delay for the retry of a failed request. Default: " + RdGlobalConfig . RETRY_DELAY + "ms\n"
27+ + " --request-timeout <milliseconds> : Hard timeout for the requests being fired by the tool before receiving any response\n"
28+ + " Default: " + RdGlobalConfig . CLIENT_REQ_TIMEOUT + "ms\n"
29+ + " --logs-path <relative/absolute path> : Directory where the '" + constants . LOGS_FOLDER + "' folder will be created\n"
30+ + " for storing logs. Default: Current Working Directory\n"
31+ + " --del-logs : Deletes any existing logs from the " + constants . LOGS_FOLDER + "/ directory and initializes\n"
32+ + " new files for logging\n"
33+ + " --help : Help for Requests Debugger Tool\n"
34+ + " --version : Version of the Requests Debugger Tool\n" ;
3135
3236 console . log ( helpOutput ) ;
3337 } ,
@@ -38,7 +42,7 @@ var CommandLineManager = {
3842
3943 /**
4044 * Processes the args from the given input array and sets the global config.
41- * @param {Array<String> } argv
45+ * @param {Array<String> } argv
4246 */
4347 processArgs : function ( argv ) {
4448
@@ -67,7 +71,7 @@ var CommandLineManager = {
6771 if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
6872 var probablePort = parseInt ( argv [ index + 1 ] ) ;
6973 if ( ! isNaN ( probablePort ) && ( probablePort <= constants . PORTS . MAX ) && ( probablePort >= constants . PORTS . MIN ) ) {
70- RdGlobalConfig . RD_HANDLER_PORT = probablePort ;
74+ RdGlobalConfig . RD_HANDLER_PROXY_PORT = probablePort ;
7175 } else {
7276 console . log ( "\nPort can only range from:" , constants . PORTS . MIN , "to:" , constants . PORTS . MAX ) ;
7377 invalidArgs . add ( '--port' ) ;
@@ -79,6 +83,24 @@ var CommandLineManager = {
7983 }
8084 }
8185
86+ // port for Requests Debugger Reverse Proxy
87+ index = argv . indexOf ( '--reverse-proxy-port' ) ;
88+ if ( index !== - 1 ) {
89+ if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
90+ var probableReverseProxyPort = parseInt ( argv [ index + 1 ] ) ;
91+ if ( ! isNaN ( probableReverseProxyPort ) && ( probableReverseProxyPort <= constants . PORTS . MAX ) && ( probableReverseProxyPort >= constants . PORTS . MIN ) ) {
92+ RdGlobalConfig . RD_HANDLER_REVERSE_PROXY_PORT = probableReverseProxyPort ;
93+ } else {
94+ console . log ( "\nPort can only range from:" , constants . PORTS . MIN , "to:" , constants . PORTS . MAX ) ;
95+ invalidArgs . add ( '--reverse-proxy-port' ) ;
96+ }
97+ argv . splice ( index , 2 ) ;
98+ } else {
99+ invalidArgs . add ( '--reverse-proxy-port' ) ;
100+ argv . splice ( index , 1 ) ;
101+ }
102+ }
103+
82104 // delay for retries in case of request failures
83105 index = argv . indexOf ( '--retry-delay' ) ;
84106 if ( index !== - 1 ) {
@@ -115,12 +137,34 @@ var CommandLineManager = {
115137 }
116138 }
117139
140+ // process proxy host
141+ index = argv . indexOf ( '--scheme' ) ;
142+ if ( index !== - 1 ) {
143+ if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
144+ var scheme = argv [ index + 1 ] ;
145+ if ( ! ( scheme === 'http' || scheme === 'https' ) ) {
146+ console . log ( "\nScheme can only be http/https" ) ;
147+ invalidArgs . add ( '--scheme' ) ;
148+ argv . splice ( index , 2 ) ;
149+ }
150+ else {
151+ RdGlobalConfig . SCHEME = scheme ;
152+ argv . splice ( index , 2 ) ;
153+ }
154+ } else {
155+ invalidArgs . add ( '--scheme' ) ;
156+ argv . splice ( index , 1 ) ;
157+ }
158+ }
159+
118160 // process proxy host
119161 index = argv . indexOf ( '--proxy-host' ) ;
120162 if ( index !== - 1 ) {
121163 if ( CommandLineManager . validArgValue ( argv [ index + 1 ] ) ) {
122164 var host = argv [ index + 1 ] ;
123- host = host . replace ( constants . PROTOCOL_REGEX , '' ) ;
165+ if ( host . lastIndexOf ( "http" ) !== 0 ) {
166+ host = 'http://' + host ;
167+ }
124168 RdGlobalConfig . proxy = RdGlobalConfig . proxy || { } ;
125169 RdGlobalConfig . proxy . host = host ;
126170 argv . splice ( index , 2 ) ;
@@ -151,7 +195,7 @@ var CommandLineManager = {
151195 argv . splice ( index , 1 ) ;
152196 }
153197 }
154-
198+
155199 // if proxy port value in invalid or doesn't exist and host exists, set the default value
156200 if ( RdGlobalConfig . proxy && RdGlobalConfig . proxy . host && ( invalidArgs . has ( '--proxy-port' ) || ! RdGlobalConfig . proxy . port ) ) {
157201 console . log ( '\nSetting Default Proxy Port:' , constants . DEFAULT_PROXY_PORT , '\n' ) ;
@@ -190,7 +234,7 @@ var CommandLineManager = {
190234 argv . splice ( index , 1 ) ;
191235 }
192236 }
193-
237+
194238 // if proxy pass is invalid or doesn't exist and username exists, set the password as empty
195239 if ( RdGlobalConfig . proxy && RdGlobalConfig . proxy . username && ( invalidArgs . has ( '--proxy-pass' ) || ! RdGlobalConfig . proxy . password ) ) {
196240 console . log ( 'Setting Proxy Password as Empty\n' ) ;
0 commit comments