Skip to content

Commit 962910d

Browse files
SNOW-2041976 Review fixes
1 parent 40ea4a8 commit 962910d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/main/java/net/snowflake/client/core/AttributeEnhancingHttpRequestRetryHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
*
1111
* <p>The execution count is stored using the key defined by {@link #EXECUTION_COUNT_ATTRIBUTE}.
1212
*/
13-
public class AttributeEnhancingHttpRequestRetryHandler extends DefaultHttpRequestRetryHandler {
13+
class AttributeEnhancingHttpRequestRetryHandler extends DefaultHttpRequestRetryHandler {
1414
/**
1515
* The key used to store the current execution count (attempt number) in the {@link HttpContext}.
1616
* Interceptors can use this key to retrieve the count. The value stored will be an {@link
1717
* Integer}.
1818
*/
19-
public static final String EXECUTION_COUNT_ATTRIBUTE =
20-
"net.snowflake.client.core.execution-count";
19+
static final String EXECUTION_COUNT_ATTRIBUTE = "net.snowflake.client.core.execution-count";
2120

2221
@Override
2322
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

src/main/java/net/snowflake/client/core/HeaderCustomizerHttpRequestInterceptor.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,17 @@ public void process(HttpRequest httpRequest, HttpContext httpContext)
7171
// convert header names to lower case for case in-sensitive lookup
7272
Set<String> protectedHeaders =
7373
currentHeaders.keySet().stream().map(String::toLowerCase).collect(Collectors.toSet());
74-
Object executionCount =
75-
httpContext.getAttribute(
74+
Integer executionCount =
75+
(Integer) httpContext.getAttribute(
7676
AttributeEnhancingHttpRequestRetryHandler.EXECUTION_COUNT_ATTRIBUTE);
77-
// If count is null or 0, it's the first attempt. Otherwise, it's a retry.
78-
boolean isRetry = (executionCount != null && (Integer) executionCount > 0);
77+
boolean isRetry = (executionCount == null || executionCount > 0);
7978

8079
for (HttpHeadersCustomizer customizer : this.headersCustomizers) {
8180
if (customizer.applies(httpMethod, uri, currentHeaders)) {
8281
if (customizer.invokeOnce() && isRetry) {
8382
logger.debug(
8483
"{} customizer should only run on the first attempt and this is a {} retry. Skipping.",
85-
customizer.getClass(),
84+
customizer.getClass().getCanonicalName(),
8685
executionCount);
8786
continue;
8887
}
@@ -157,18 +156,22 @@ private static void throwIfExistingHeadersAreModified(
157156
Set<String> protectedHeaders, Set<String> newHeaders, HttpHeadersCustomizer customizer) {
158157
for (String headerName : newHeaders) {
159158
if (headerName != null && protectedHeaders.contains(headerName.toLowerCase())) {
159+
String customizerName = customizer.getClass().getCanonicalName();
160160
logger.debug(
161161
"Customizer {} attempted to override existing driver header: {}",
162-
customizer.getClass().getName(),
162+
customizerName,
163163
headerName);
164-
throw new DriverHeaderOverridingNotAllowedException(headerName);
164+
throw new DriverHeaderOverridingNotAllowedException(headerName, customizerName);
165165
}
166166
}
167167
}
168168

169169
public static class DriverHeaderOverridingNotAllowedException extends RuntimeException {
170-
public DriverHeaderOverridingNotAllowedException(String header) {
171-
super(String.format("Driver headers overriding not allowed. Tried for header: %s", header));
170+
public DriverHeaderOverridingNotAllowedException(String header, String customizerName) {
171+
super(
172+
String.format(
173+
"Driver headers overriding not allowed. Tried for header: %s in customizer: {}",
174+
header, customizerName));
172175
}
173176
}
174177
}

0 commit comments

Comments
 (0)