@@ -44,9 +44,8 @@ static void s_printHelp()
44
44
stdout,
45
45
" signing_region: used for websocket signer it should only be specific if websockets are used. (required for "
46
46
" websockets)\n " );
47
- fprintf (stdout, " proxy_host: if you want to use a proxy with websockets, specify the host here (optional).\n " );
48
- fprintf (
49
- stdout, " proxy_port: defaults to 8080 is proxy_host is set. Set this to any value you'd like (optional).\n " );
47
+ fprintf (stdout, " proxy_host: host name of the http proxy to use (optional).\n " );
48
+ fprintf (stdout, " proxy_port: port of the http proxy to use (optional).\n " );
50
49
51
50
fprintf (stdout, " x509: Use the x509 credentials provider while using websockets (optional)\n " );
52
51
fprintf (stdout, " x509_role_alias: Role alias to use with the x509 credentials provider (required for x509)\n " );
@@ -155,15 +154,19 @@ int main(int argc, char *argv[])
155
154
}
156
155
useWebSocket = true ;
157
156
signingRegion = s_getCmdOption (argv, argv + argc, " --signing_region" );
157
+ }
158
158
159
- if (s_cmdOptionExists (argv, argv + argc, " --proxy_host" ))
160
- {
161
- proxyHost = s_getCmdOption (argv, argv + argc, " --proxy_host" );
162
- }
159
+ if (s_cmdOptionExists (argv, argv + argc, " --proxy_host" ))
160
+ {
161
+ proxyHost = s_getCmdOption (argv, argv + argc, " --proxy_host" );
162
+ }
163
163
164
- if (s_cmdOptionExists (argv, argv + argc, " --proxy_port" ))
164
+ if (s_cmdOptionExists (argv, argv + argc, " --proxy_port" ))
165
+ {
166
+ int port = atoi (s_getCmdOption (argv, argv + argc, " --proxy_port" ));
167
+ if (port > 0 && port <= UINT16_MAX)
165
168
{
166
- proxyPort = static_cast <uint16_t >(atoi ( s_getCmdOption (argv, argv + argc, " --proxy_port " )) );
169
+ proxyPort = static_cast <uint16_t >(port );
167
170
}
168
171
}
169
172
@@ -265,6 +268,14 @@ int main(int argc, char *argv[])
265
268
exit (-1 );
266
269
}
267
270
271
+ Aws::Crt::Http::HttpClientConnectionProxyOptions proxyOptions;
272
+ if (!proxyHost.empty ())
273
+ {
274
+ proxyOptions.HostName = proxyHost;
275
+ proxyOptions.Port = proxyPort;
276
+ proxyOptions.AuthType = Aws::Crt::Http::AwsHttpProxyAuthenticationType::None;
277
+ }
278
+
268
279
Aws::Crt::Io::TlsContext x509TlsCtx;
269
280
Aws::Iot::MqttClientConnectionConfigBuilder builder;
270
281
@@ -275,15 +286,6 @@ int main(int argc, char *argv[])
275
286
else if (useWebSocket)
276
287
{
277
288
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider = nullptr ;
278
-
279
- Aws::Crt::Http::HttpClientConnectionProxyOptions proxyOptions;
280
- if (!proxyHost.empty ())
281
- {
282
- proxyOptions.HostName = proxyHost;
283
- proxyOptions.Port = proxyPort;
284
- proxyOptions.AuthType = Aws::Crt::Http::AwsHttpProxyAuthenticationType::None;
285
- }
286
-
287
289
if (useX509)
288
290
{
289
291
Aws::Crt::Io::TlsContextOptions tlsCtxOptions =
@@ -351,18 +353,18 @@ int main(int argc, char *argv[])
351
353
}
352
354
353
355
Aws::Iot::WebsocketConfig config (signingRegion, provider);
354
- if (!proxyHost.empty ())
355
- {
356
- config.ProxyOptions = proxyOptions;
357
- }
358
-
359
356
builder = Aws::Iot::MqttClientConnectionConfigBuilder (config);
360
357
}
361
358
else
362
359
{
363
360
s_printHelp ();
364
361
}
365
362
363
+ if (!proxyHost.empty ())
364
+ {
365
+ builder.WithHttpProxyOptions (proxyOptions);
366
+ }
367
+
366
368
if (!caFile.empty ())
367
369
{
368
370
builder.WithCertificateAuthority (caFile.c_str ());
0 commit comments