Skip to content
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

Apache http client should allow nonProxyHost configuration #381

Closed
xxxyyyz opened this issue May 2, 2018 · 9 comments
Closed

Apache http client should allow nonProxyHost configuration #381

xxxyyyz opened this issue May 2, 2018 · 9 comments
Assignees
Milestone

Comments

@xxxyyyz
Copy link
Contributor

xxxyyyz commented May 2, 2018

It's currently not possible to configure exceptions from proxy configuration.
Would be great if system property http.nonProxyHosts could be used to list local hosts

@ptrthomas ptrthomas added this to the v0.8.0 milestone May 2, 2018
@ptrthomas
Copy link
Member

would be great if someone can volunteer to at least recommend where the fix should be made.

@xxxyyyz
Copy link
Contributor Author

xxxyyyz commented May 2, 2018

I patched ApacheHttpClient locally:

    public void configure(HttpConfig config, ScriptContext context) {
        clientBuilder = HttpClientBuilder.create();

        List<String> proxyExceptions = Arrays.asList("host1|host2|host3".split("\\|"));
        ProxySelector proxySelector = new ProxySelector() {
            @Override
            public List<Proxy> select(URI uri) {
                return Collections.singletonList(proxyExceptions.contains(uri.getHost()) ? Proxy.NO_PROXY : new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-host", 3128)));
            }

            @Override
            public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
                context.logger.info("Connect to {} failed", uri, ioe);
            }
        };
        clientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(proxySelector));
        clientBuilder.useSystemProperties();

I didn't take the time to dig into configuration stuff of karate project, though - surely you know better than me how to read system property "http.nonProxyHosts" to build proxyExceptions list.
It's also considerable to use system default proxy rather than creating one in method select(URI) ...

Hope this helps a bit

Cheers
Jürgen

@ptrthomas
Copy link
Member

@xxxyyyz awesome, exactly what I needed, thanks.

@ptrthomas
Copy link
Member

@xxxyyyz Jürgen would it be possible for you to review the commit and check if it works for you. it would be too much effort for me to set this up

@ptrthomas ptrthomas self-assigned this May 4, 2018
@xxxyyyz
Copy link
Contributor Author

xxxyyyz commented May 9, 2018

@ptrthomas Peter, thanks for your quick fix and response!
I will be glad to verify your patch, but I'm currently on vacation.
Will be doing so next week!

@ptrthomas
Copy link
Member

also refer PR #393

@ptrthomas
Copy link
Member

released 0.8.0

@rushaliuser
Copy link

Upgraded Karate to 0.9.2 version and below line giving error;

public void configure(HttpConfig config, ScriptContext context)

Can someone help to resolve?

@ptrthomas
Copy link
Member

@rushaliuser please use stack overflow or follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants