-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-1868467: Add custom headers #2016
base: master
Are you sure you want to change the base?
Conversation
add headers and support crt
# Conflicts: # pom.xml
# Conflicts: # pom.xml
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I left some comments.
Could you also provide some tests for the provided features?
@@ -1,1507 +1,1507 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should not be so many changes in pom.xml files - probably it's an unwanted change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only whitespace, I'll reformat
@@ -63,6 +63,7 @@ public enum SFSessionProperty { | |||
@Deprecated | |||
PRIVATE_KEY_FILE_PWD("private_key_file_pwd", false, String.class), | |||
PRIVATE_KEY_PWD("private_key_pwd", false, String.class), | |||
AdditionalHttpHeaders("additional_http_headers", false, String.class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should follow the enum naming convention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if (headers != null && !headers.isEmpty()) { | ||
Map<String, String> headersMap = new HashMap<>(); | ||
for (String headerKeyPair : headers.split(";")) { | ||
String[] split = headerKeyPair.split(":"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the value contains ':' or ';' internally? than the simple split could be not sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we need to agree on some separator, since this is map of string string.
what do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ';' and ':' may be easy to read but e.g. ';' is used in some headers as a separator inside the fields
maybe we can think about url encoded parameters with '&' and =
as separators - then we could expect that all property values are encoded separately and also the whole property value is encoded e.g.
static Map<String, String> getHttpHeaders(String headers) {
if (headers != null && !headers.isEmpty()) {
Map<String, String> headersMap = new HashMap<>();
for (String headerKeyPair : java.net.URLDecoder.decode(headers).split("&")) {
String[] split = headerKeyPair.split("=");
if (split.length >= 2) {
headersMap.put(split[0], java.net.URLDecoder.decode(split[1]));
}
}
return headersMap;
}
return null;
}
public static void main(String[] args){
String headers = java.net.URLEncoder.encode("x="+java.net.URLEncoder.encode("test=&123")+"&y="+java.net.URLEncoder.encode("t&12=3"));
System.out.println(getHttpHeaders(headers));
}
Please note that signing the CLA is also necessary for your PR to be merged |
I have read the CLA Document and I hereby sign the CLA |
@@ -812,6 +814,29 @@ public synchronized void open() throws SFException, SnowflakeSQLException { | |||
logger.debug("Session {} opened in {} ms.", getSessionId(), stopwatch.elapsedMillis()); | |||
} | |||
|
|||
public Map<String, String> getHttpHeaders() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if newly added methods need to be public please mark them with @SnowflakeJdbcInternalApi
I have read the CLA Document and I hereby sign the CLA |
Overview
SNOW-1868467
Pre-review self checklist
master
branchmvn -P check-style validate
)mvn verify
and inspecttarget/japicmp/japicmp.html
)SNOW-XXXX:
External contributors - please answer these questions before submitting a pull request. Thanks!
What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Issue: #2015
Fill out the following pre-review checklist:
@SnowflakeJdbcInternalApi
(note that public/protected methods/fields in classes marked with this annotation are already internal)Please describe how your code solves the related issue.
There is no options to add custom headers on each snowflake request (login, query, telemetry, heartbeat etc..)
This is needed in our case because we are calling snowflake from proxy and proxy enforce us to add jwt in some custom header.
This change
add an option to add map of custom headers in session coonig.
make sure headers are added on each request