Skip to content

Commit 5309c2d

Browse files
authored
Merge pull request #509 from gcuisinier/use-noproxyhost-configuration
Use No Proxy Hosts configuration, fixes #459
2 parents f5e7891 + 78e9ced commit 5309c2d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main/java/hudson/plugins/jira/JiraRestService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,13 @@ private Request buildGetRequest(URI uri) {
445445
ProxyConfiguration proxyConfiguration = Jenkins.get().proxy;
446446
if ( proxyConfiguration != null ) {
447447
final HttpHost proxyHost = new HttpHost( proxyConfiguration.name, proxyConfiguration.port );
448-
request.viaProxy(proxyHost);
448+
449+
boolean shouldByPassProxy = proxyConfiguration.getNoProxyHostPatterns().stream().anyMatch(
450+
it -> it.matcher(uri.getHost()).matches()
451+
);
452+
453+
if(!shouldByPassProxy)
454+
request.viaProxy(proxyHost);
449455
}
450456

451457
return request

src/test/java/hudson/plugins/jira/JiraRestServiceProxyTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public void withProxy() throws Exception {
6363
assertEquals(localPort, proxyHost.getPort());
6464
}
6565

66+
@Test
67+
public void withProxyAndNoProxyHosts() throws Exception {
68+
int localPort = connector.getLocalPort();
69+
Jenkins.get().proxy = new ProxyConfiguration("localhost", localPort);
70+
Jenkins.get().proxy.setNoProxyHost("example.com|google.com");
71+
72+
73+
assertNull(getProxyObjectFromRequest());
74+
75+
}
76+
77+
6678
@Test
6779
public void withoutProxy() throws Exception {
6880
assertNull(getProxyObjectFromRequest());
@@ -76,7 +88,7 @@ private Object getProxyObjectFromRequest()
7688
Method m = service.getClass().getDeclaredMethod("buildGetRequest", URI.class);
7789
m.setAccessible(true);
7890

79-
Request buildGetRequestValue = (Request) m.invoke(service, URI.create(""));
91+
Request buildGetRequestValue = (Request) m.invoke(service, JIRA_URI);
8092

8193
assertNotNull(buildGetRequestValue);
8294

0 commit comments

Comments
 (0)