case "host": if (member.getValue() instanceof String) { obj.setHost((String)member.getValue());
@Override public void start() throws Exception { HttpClientRequest request = vertx.createHttpClient(new HttpClientOptions() .setSsl(true) .setTrustAll(true) .setVerifyHost(false) .setProxyOptions(new ProxyOptions() .setType(ProxyType.HTTP) .setHost("localhost") .setPort(8080))) .put(8282, "localhost", "/", resp -> { System.out.println("Got response " + resp.statusCode()); resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1"))); }); request.setChunked(true); for (int i = 0; i < 10; i++) { request.write("client-chunk-" + i); } request.end(); } }
@Test public void testProxyConnectError() { testConnectErrorNotifiesOnEventLoop(new NetClientOptions() .setProxyOptions(new ProxyOptions() .setPort(1234) .setType(ProxyType.SOCKS5) .setHost("localhost"))); }
private void proxyTest(int error, String username, String url, Handler<AsyncResult<HttpClientResponse>> assertResponse) throws Exception { startProxy(error, username); final HttpClientOptions options = new HttpClientOptions() .setSsl(url.startsWith("https")) .setProxyOptions(new ProxyOptions() .setType(ProxyType.HTTP) .setHost("localhost") .setPort(proxy.getPort())); HttpClient client = vertx.createHttpClient(options); client.getAbs(url, assertResponse).end(); await(); }
@Test public void testHttpSocksProxyRequest() throws Exception { startProxy(null, ProxyType.SOCKS5); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.SOCKS5).setHost("localhost").setPort(proxy.getPort()))); server.requestHandler(req -> { req.response().end(); }); server.listen(onSuccess(s -> { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(resp -> { assertEquals(200, resp.statusCode()); assertNotNull("request did not go through proxy", proxy.getLastUri()); testComplete(); })).exceptionHandler(th -> fail(th)).end(); })); await(); }
@Test public void testHttpProxyRequest() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); testHttpProxyRequest2(handler -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", handler)); }
@Test public void testHttpSocksProxyRequestAuth() throws Exception { startProxy("user", ProxyType.SOCKS5); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.SOCKS5).setHost("localhost").setPort(proxy.getPort()) .setUsername("user").setPassword("user"))); server.requestHandler(req -> { req.response().end(); }); server.listen(onSuccess(s -> { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(resp -> { assertEquals(200, resp.statusCode()); assertNotNull("request did not go through proxy", proxy.getLastUri()); testComplete(); })).exceptionHandler(th -> fail(th)).end(); })); await(); }
@Test public void testPerPeerPoolingWithProxy() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false).setProxyOptions(new ProxyOptions() .setType(ProxyType.HTTP) .setHost(DEFAULT_HTTP_HOST) .setPort(DEFAULT_HTTP_PORT))); testPerXXXPooling((i, handler) -> client.get(80, "host" + i, "/somepath", handler), HttpServerRequest::host); }
@Test public void testHttpProxyFtpRequest() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); final String url = "ftp://ftp.gnu.org/gnu/"; proxy.setForceUri("http://localhost:8080/"); server.requestHandler(req -> { req.response().end(); }); server.listen(onSuccess(s -> { HttpClientRequest clientReq = client.getAbs(url, onSuccess(resp -> { assertEquals(200, resp.statusCode()); assertEquals("request did sent the expected url", url, proxy.getLastUri()); testComplete(); })); clientReq.exceptionHandler(this::fail); clientReq.end(); })); await(); }
@Test public void testHttpProxyRequestAuth() throws Exception { startProxy("user", ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()) .setUsername("user").setPassword("user"))); server.requestHandler(req -> { req.response().end(); }); server.listen(onSuccess(s -> { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(resp -> { assertEquals(200, resp.statusCode()); assertNotNull("request did not go through proxy", proxy.getLastUri()); assertEquals("Host header doesn't contain target host", "localhost:8080", proxy.getLastRequestHeaders().get("Host")); testComplete(); })).exceptionHandler(th -> fail(th)).end(); })); await(); }
@Test public void testHttpProxyRequestOverrideClientSsl() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setSsl(true).setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); testHttpProxyRequest2(handler -> client.get(new RequestOptions().setSsl(false).setHost("localhost").setPort(8080), handler)); }
@Test public void testCopyProxyOptions() { ProxyOptions options = new ProxyOptions(); options.setType(randType); options.setHost(randHost); options.setPort(randPort); options.setUsername(randUsername); options.setPassword(randPassword); ProxyOptions copy = new ProxyOptions(options); assertEquals(randType, copy.getType()); assertEquals(randPort, copy.getPort()); assertEquals(randHost, copy.getHost()); assertEquals(randUsername, copy.getUsername()); assertEquals(randPassword, copy.getPassword()); }
.setProxyOptions(new ProxyOptions().setType(ProxyType.SOCKS5).setHost("127.0.0.1").setPort(11080)) .setTrustOptions(Trust.SERVER_JKS_ROOT_CA.get()); NetClient client = vertx.createNetClient(clientOptions);
.setHostnameVerificationAlgorithm("HTTPS") .setSsl(true) .setProxyOptions(new ProxyOptions().setType(ProxyType.SOCKS5).setHost("127.0.0.1").setPort(11080)) .setTrustOptions(Trust.SERVER_JKS_ROOT_CA.get()); NetClient client = vertx.createNetClient(clientOptions);
@Test public void testProxyOptions() { ProxyOptions options = new ProxyOptions(); assertEquals(ProxyOptions.DEFAULT_TYPE, options.getType()); assertEquals(options, options.setType(randType)); assertEquals(randType, options.getType()); assertNullPointerException(() -> options.setType(null)); assertEquals(ProxyOptions.DEFAULT_HOST, options.getHost()); assertEquals(options, options.setHost(randHost)); assertEquals(randHost, options.getHost()); assertNullPointerException(() -> options.setHost(null)); assertEquals(ProxyOptions.DEFAULT_PORT, options.getPort()); assertEquals(options, options.setPort(randPort)); assertEquals(randPort, options.getPort()); assertIllegalArgumentException(() -> options.setPort(-1)); assertIllegalArgumentException(() -> options.setPort(65536)); assertEquals(null, options.getUsername()); assertEquals(options, options.setUsername(randUsername)); assertEquals(randUsername, options.getUsername()); assertEquals(null, options.getPassword()); assertEquals(options, options.setPassword(randPassword)); assertEquals(randPassword, options.getPassword()); }
@Test public void testProxyConnectError() { testConnectErrorNotifiesOnEventLoop(new NetClientOptions() .setProxyOptions(new ProxyOptions() .setPort(1234) .setType(ProxyType.SOCKS5) .setHost("localhost"))); }
@Test public void testHttpProxyRequest() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); testHttpProxyRequest2(client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/")); }
@Test public void testPerPeerPoolingWithProxy() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false).setProxyOptions(new ProxyOptions() .setType(ProxyType.HTTP) .setHost(DEFAULT_HTTP_HOST) .setPort(DEFAULT_HTTP_PORT))); testPerXXXPooling(i -> client.get(80, "host" + i, "/somepath"), HttpServerRequest::host); }
@Test public void testHttpProxyRequestOverrideClientSsl() throws Exception { startProxy(null, ProxyType.HTTP); client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setSsl(true).setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort()))); testHttpProxyRequest2(client.get(new RequestOptions().setSsl(false).setHost("localhost").setPort(8080))); }