Skip to content

Commit

Permalink
Add custom header to any request
Browse files Browse the repository at this point in the history
  • Loading branch information
bpackter committed Dec 25, 2024
1 parent a452407 commit 05a6693
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import java.sql.SQLException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -815,14 +815,16 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
}

public Map<String, String> getHttpHeaders() {
if (getConnectionPropertiesMap() != null && getConnectionPropertiesMap().get(SFSessionProperty.AdditionalHttpHeaders) != null) {
return getHttpHeaders((String) getConnectionPropertiesMap().get(SFSessionProperty.AdditionalHttpHeaders));
if (getConnectionPropertiesMap() != null
&& getConnectionPropertiesMap().get(SFSessionProperty.AdditionalHttpHeaders) != null) {
return getHttpHeaders(
(String) getConnectionPropertiesMap().get(SFSessionProperty.AdditionalHttpHeaders));
}
return Collections.emptyMap();
}

public Map<String, String> getHttpHeaders(String headers) {
if(headers!=null && !headers.isEmpty()) {
if (headers != null && !headers.isEmpty()) {
Map<String, String> headersMap = new HashMap<>();
for (String headerKeyPair : headers.split(";")) {
String[] split = headerKeyPair.split(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,12 @@ private void parseChunkFiles(JsonNode rootNode, SFBaseStatement sfStatement) {
}

if (sfStatement.getSFBaseSession() instanceof SFSession) {
Map<String, String> httpHeaders = ((SFSession) sfStatement.getSFBaseSession()).getHttpHeaders();
Map<String, String> httpHeaders =
((SFSession) sfStatement.getSFBaseSession()).getHttpHeaders();
if (httpHeaders != null) {
for (Map.Entry<String, String> httpHeader : httpHeaders.entrySet()) {
logger.debug(
"Add header key: {}, value: {}",
httpHeader.getKey(),
httpHeader.getValue());
"Add header key: {}, value: {}", httpHeader.getKey(), httpHeader.getValue());
this.chunkHeadersMap.put(httpHeader.getKey(), httpHeader.getValue());
}
}
Expand Down

0 comments on commit 05a6693

Please sign in to comment.