-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into samikshya-db/newmergedChanges
- Loading branch information
Showing
11 changed files
with
265 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
databricks-sdk-java/src/main/java/com/databricks/sdk/core/utils/CustomRoutePlanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.databricks.sdk.core.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import org.apache.http.HttpException; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.HttpRequest; | ||
import org.apache.http.conn.routing.HttpRoute; | ||
import org.apache.http.conn.routing.HttpRoutePlanner; | ||
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
/** | ||
* Custom route planner that routes requests via a proxy, except for hosts that match a list of | ||
* non-proxy hosts. | ||
*/ | ||
public class CustomRoutePlanner implements HttpRoutePlanner { | ||
private final DefaultProxyRoutePlanner defaultRoutePlanner; | ||
private final List<Pattern> nonProxyHostRegex; | ||
|
||
public CustomRoutePlanner(HttpHost proxy, String nonProxyHosts) { | ||
this.defaultRoutePlanner = new DefaultProxyRoutePlanner(proxy); | ||
if (nonProxyHosts == null || nonProxyHosts.isEmpty()) { | ||
this.nonProxyHostRegex = new ArrayList<>(); | ||
} else { | ||
this.nonProxyHostRegex = | ||
Arrays.stream(nonProxyHosts.split("\\|")) | ||
.map(host -> host.replace(".", "\\.").replace("*", ".*")) | ||
.map(Pattern::compile) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
||
@Override | ||
public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) | ||
throws HttpException { | ||
String targetHostName = target.getHostName(); | ||
if (nonProxyHostRegex.stream().anyMatch(pattern -> pattern.matcher(targetHostName).matches())) { | ||
return new HttpRoute(target); // Direct route, no proxy | ||
} | ||
return defaultRoutePlanner.determineRoute(target, request, context); // Route via proxy | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.