Skip to content

Commit

Permalink
KNOX-3007 - Make http client cookie spec parameter configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroflag committed Feb 19, 2024
1 parent d3f5a56 commit b227fca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
private static final String HTTP_CLIENT_MAX_CONNECTION = GATEWAY_CONFIG_FILE_PREFIX + ".httpclient.maxConnections";
private static final String HTTP_CLIENT_CONNECTION_TIMEOUT = GATEWAY_CONFIG_FILE_PREFIX + ".httpclient.connectionTimeout";
private static final String HTTP_CLIENT_SOCKET_TIMEOUT = GATEWAY_CONFIG_FILE_PREFIX + ".httpclient.socketTimeout";
private static final String HTTP_CLIENT_COOKIE_SPEC = GATEWAY_CONFIG_FILE_PREFIX + ".httpclient.cookieSpec";
private static final String THREAD_POOL_MAX = GATEWAY_CONFIG_FILE_PREFIX + ".threadpool.max";
public static final String HTTP_SERVER_REQUEST_BUFFER = GATEWAY_CONFIG_FILE_PREFIX + ".httpserver.requestBuffer";
public static final String HTTP_SERVER_REQUEST_HEADER_BUFFER = GATEWAY_CONFIG_FILE_PREFIX + ".httpserver.requestHeaderBuffer";
Expand Down Expand Up @@ -1565,4 +1566,9 @@ public int getTokenMigrationProgressCount() {
return getInt(TOKEN_MIGRATION_PROGRESS_COUNT, 10);
}

@Override
public String getHttpClientCookieSpec() {
return get(HTTP_CLIENT_COOKIE_SPEC, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1106,4 +1106,9 @@ public int getTokenMigrationProgressCount() {
return 1;
}

@Override
public String getHttpClientCookieSpec() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public interface SpiGatewayMessages {
@Message( level = MessageLevel.INFO, text = "HTTP client socket timeout is set to {0} ms for {1}" )
void setHttpClientSocketTimeout(int socketTimeout, String serviceRole);

@Message( level = MessageLevel.INFO, text = "HTTP client cookie spec is set to {0}" )
void setHttpClientCookieSpec(String cookieSpec);

@Message( level = MessageLevel.INFO, text = "replayBufferSize is set to {0} for {1}" )
void setReplayBufferSize(int replayBufferSize, String serviceRole);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,8 @@ public interface GatewayConfig {
*/
int getTokenMigrationProgressCount();

/**
* @return CookieSpec for the HTTP client used by the dispatch, see org.apache.http.client.config.CookieSpecs
*/
String getHttpClientCookieSpec();
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ static RequestConfig getRequestConfig(FilterConfig config, String serviceRole) {
builder.setSocketTimeout( socketTimeout );
LOG.setHttpClientSocketTimeout(socketTimeout, serviceRole == null ? "N/A" : serviceRole);
}
String cookieSpec = getCookieSpec(config);
if (cookieSpec != null) {
LOG.setHttpClientCookieSpec(cookieSpec);
builder.setCookieSpec(cookieSpec);
}

// HttpClient 4.5.7 is broken for %2F handling with url normalization.
// However, HttpClient 4.5.8+ (HTTPCLIENT-1968) has reasonable url
Expand Down Expand Up @@ -369,4 +374,12 @@ private static long parseTimeout( String s ) {
Period p = Period.parse( s, f );
return p.toStandardDuration().getMillis();
}

private static String getCookieSpec(FilterConfig filterConfig) {
GatewayConfig globalConfig =
(GatewayConfig)filterConfig.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
return globalConfig != null
? globalConfig.getHttpClientCookieSpec()
: filterConfig.getInitParameter("httpclient.cookieSpec");
}
}

0 comments on commit b227fca

Please sign in to comment.