Skip to content

Commit

Permalink
Add ENV Proxy Option to HTTP Connection Manager (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Sep 18, 2023
1 parent 6288900 commit f4fb56a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crt/s2n
Submodule s2n updated from baf094 to f7930e
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
proxyAuthorizationPassword = proxyOptions.getAuthorizationPassword();
}

int environmentVariableProxyConnectionType = 0;
TlsConnectionOptions environmentVariableProxyTlsConnectionOptions = null;
int environmentVariableType = 0;
HttpProxyEnvironmentVariableSetting environmentVariableSetting = options.getHttpProxyEnvironmentVariableSetting();
if (environmentVariableSetting != null) {
environmentVariableProxyConnectionType = environmentVariableSetting.getConnectionType().getValue();
environmentVariableProxyTlsConnectionOptions = environmentVariableSetting.getTlsConnectionOptions();
environmentVariableType = environmentVariableSetting.getEnvironmentVariableType().getValue();
}

HttpMonitoringOptions monitoringOptions = options.getMonitoringOptions();
long monitoringThroughputThresholdInBytesPerSecond = 0;
int monitoringFailureIntervalInSeconds = 0;
Expand All @@ -117,6 +127,11 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
proxyAuthorizationType,
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
environmentVariableProxyConnectionType,
environmentVariableProxyTlsConnectionOptions != null
? environmentVariableProxyTlsConnectionOptions.getNativeHandle()
: 0,
environmentVariableType,
options.isManualWindowManagement(),
options.getMaxConnectionIdleInMilliseconds(),
monitoringThroughputThresholdInBytesPerSecond,
Expand Down Expand Up @@ -245,6 +260,9 @@ private static native long httpClientConnectionManagerNew(HttpClientConnectionMa
int proxyAuthorizationType,
byte[] proxyAuthorizationUsername,
byte[] proxyAuthorizationPassword,
int environmentVariableProxyConnectionType,
long environmentVariableProxyTlsConnectionOptions,
int environmentVariableSetting,
boolean isManualWindowManagement,
long maxConnectionIdleInMilliseconds,
long monitoringThroughputThresholdInBytesPerSecond,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class HttpClientConnectionManagerOptions {
private int port = -1;
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
private HttpProxyOptions proxyOptions;
private HttpProxyEnvironmentVariableSetting httpProxyEnvironmentVariableSetting;
private boolean manualWindowManagement = false;
private HttpMonitoringOptions monitoringOptions;
private long maxConnectionIdleInMilliseconds = 0;
Expand Down Expand Up @@ -200,6 +201,30 @@ public HttpClientConnectionManagerOptions withProxyOptions(HttpProxyOptions prox
*/
public HttpProxyOptions getProxyOptions() { return proxyOptions; }

/**
* Optional.
* Sets how proxy is fetched from the environment.
* Reading proxy configuration from environment is disabled if this is NULL for backward compatibility.
* Only works when proxyOptions is not set. The proxy settings follow the following precedence
* 1. Configured Proxy Setting
* 2. Environment (if enabled)
* 3. No proxy
* @param httpProxyEnvironmentVariableSetting for this connection manager
* @return this
*/
public HttpClientConnectionManagerOptions withProxyEnvironmentVariableSetting(
HttpProxyEnvironmentVariableSetting httpProxyEnvironmentVariableSetting) {
this.httpProxyEnvironmentVariableSetting = httpProxyEnvironmentVariableSetting;
return this;
}

/**
* @return the proxy environment variable setting
*/
public HttpProxyEnvironmentVariableSetting getHttpProxyEnvironmentVariableSetting() {
return httpProxyEnvironmentVariableSetting;
}

/**
* @return true if manual window management is used, false otherwise
* @see #withManualWindowManagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public HttpProxyEnvironmentVariableSetting() {
}

/**
* Sets the proxy connection type
* (Optional)
* Sets the proxy connection type. Defaults to HttpProxyConnectionType.Legacy
* @param connectionType what kind of connection to establish
*/
public void setConnectionType(HttpProxyConnectionType connectionType) {
Expand All @@ -79,11 +80,17 @@ public HttpProxyEnvironmentVariableType getEnvironmentVariableType() {
return environmentVariableType;
}

/**
* (Optional)
* Enable/Disable reading from environment variable for Proxy config. Defaults to Enabled
* @param environmentVariableType enable or disable env proxy
*/
public void setEnvironmentVariableType(HttpProxyEnvironmentVariableType environmentVariableType) {
this.environmentVariableType = environmentVariableType;
}

/**
* (Optional)
* Sets the tls connection options for the proxy connection
*
* @param tlsConnectionOptions tls connection options for the proxy connection
Expand Down
15 changes: 15 additions & 0 deletions src/native/http_connection_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <aws/http/connection_manager.h>
#include <aws/http/http.h>
#include <aws/http/proxy.h>
#include <http_proxy_options_environment_variable.h>

#include "http_connection_manager.h"

Expand Down Expand Up @@ -107,6 +108,9 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
jint jni_proxy_authorization_type,
jbyteArray jni_proxy_authorization_username,
jbyteArray jni_proxy_authorization_password,
jint jni_environment_variable_proxy_connection_type,
jlong jni_environment_variable_proxy_tls_connection_options,
jint jni_environment_variable_type,
jboolean jni_manual_window_management,
jlong jni_max_connection_idle_in_milliseconds,
jlong jni_monitoring_throughput_threshold_in_bytes_per_second,
Expand Down Expand Up @@ -222,6 +226,17 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
manager_options.proxy_options = &proxy_options;
}

struct proxy_env_var_settings proxy_ev_settings;
AWS_ZERO_STRUCT(proxy_ev_settings);

aws_http_proxy_environment_variable_setting_jni_init(
&proxy_ev_settings,
jni_environment_variable_proxy_connection_type,
jni_environment_variable_type,
(struct aws_tls_connection_options *)jni_environment_variable_proxy_tls_connection_options);

manager_options.proxy_ev_settings = &proxy_ev_settings;

binding->manager = aws_http_connection_manager_new(allocator, &manager_options);
if (binding->manager == NULL) {
aws_jni_throw_runtime_exception(
Expand Down

0 comments on commit f4fb56a

Please sign in to comment.