-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow proxy no proxy host configuration (#745)
- Loading branch information
1 parent
f12f0db
commit 18613e3
Showing
2 changed files
with
49 additions
and
3 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
47 changes: 47 additions & 0 deletions
47
src/main/java/jenkins/plugins/slack/NoProxyHostCheckerRoutePlanner.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,47 @@ | ||
package jenkins.plugins.slack; | ||
|
||
import hudson.ProxyConfiguration; | ||
import java.util.regex.Pattern; | ||
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.impl.conn.DefaultRoutePlanner; | ||
import org.apache.http.impl.conn.DefaultSchemePortResolver; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
public class NoProxyHostCheckerRoutePlanner implements HttpRoutePlanner { | ||
|
||
private DefaultProxyRoutePlanner defaultProxyRoutePlanner = null; | ||
private DefaultRoutePlanner defaultRoutePlanner = null; | ||
private String noProxyHost = null; | ||
|
||
public NoProxyHostCheckerRoutePlanner(String noProxyHost, HttpHost host){ | ||
defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(host); | ||
defaultRoutePlanner = new DefaultRoutePlanner(new DefaultSchemePortResolver()); | ||
this.noProxyHost = noProxyHost; | ||
} | ||
|
||
public void setProxy(HttpHost host){ | ||
defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(host); | ||
} | ||
|
||
public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws org.apache.http.HttpException { | ||
final String targetHostUri = target.toURI(); | ||
if(isNoProxyHost(targetHostUri)) | ||
return defaultRoutePlanner.determineRoute(target,request,context); | ||
return defaultProxyRoutePlanner.determineRoute(target,request,context); | ||
} | ||
|
||
private boolean isNoProxyHost(String host) { | ||
if (host!=null && noProxyHost!=null) { | ||
for (Pattern p : ProxyConfiguration.getNoProxyHostPatterns(noProxyHost)) { | ||
if (p.matcher(host).matches()) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |