/** * Get port from provided {@link URI}. * <p> * Expected schemes are {@code "ws"} and {@code "wss"} and this method will return {@code 80} or * {@code 443} when the port is not explicitly set in the provided {@link URI}. * * @param uri provided uri. * @return port number which should be used for creating connections/etc. */ public static int getWsPort(URI uri) { return getWsPort(uri, uri.getScheme()); }
/** * Get port from provided {@link URI}. * <p> * Expected schemes are {@code "ws"} and {@code "wss"} and this method will return {@code 80} or * {@code 443} when the port is not explicitly set in the provided {@link URI}. * * @param uri provided uri. * @return port number which should be used for creating connections/etc. */ public static int getWsPort(URI uri) { return getWsPort(uri, uri.getScheme()); }
@Override public String getRequestUri() { final int requestPort = Utils.getWsPort(uri); return String.format("%s:%d", uri.getHost(), requestPort); }
private SocketAddress getServerAddress(URI uri) throws DeploymentException { int port = Utils.getWsPort(uri); try { return new InetSocketAddress(uri.getHost(), port); } catch (IllegalArgumentException e) { throw new DeploymentException(e.getMessage(), e); } }
int port = Utils.getWsPort(uri); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, String.format("Not using proxy for URI '%s'.", uri));
int port = Utils.getWsPort(uri); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, String.format("Not using proxy for URI '%s'.", uri));
scheme = "wss"; int port = Utils.getWsPort(location, scheme); location = new URI(scheme, location.getUserInfo(), location.getHost(), port, location .getPath(), location.getQuery(), location.getFragment());
scheme = "wss"; int port = Utils.getWsPort(location, scheme); location = new URI(scheme, location.getUserInfo(), location.getHost(), port, location .getPath(), location.getQuery(), location.getFragment());
case DIRECT: try { connectAddress = new InetSocketAddress(requestURI.getHost(), Utils.getWsPort(requestURI)); } catch (IllegalArgumentException e) { closeTransport(privateTransport);
case DIRECT: try { connectAddress = new InetSocketAddress(requestURI.getHost(), Utils.getWsPort(requestURI)); } catch (IllegalArgumentException e) { closeTransport(privateTransport);
private NextAction sendRequest(FilterChainContext ctx, UpgradeRequest upgradeRequest) { HttpRequestPacket.Builder builder = HttpRequestPacket.builder(); if (proxy && !PROXY_CONNECTED.get(ctx.getConnection())) { UPGRADE_REQUEST.set(ctx.getConnection(), upgradeRequest); URI requestURI = upgradeRequest.getRequestURI(); final int requestPort = Utils.getWsPort(requestURI); builder = builder.uri(String.format("%s:%d", requestURI.getHost(), requestPort)); builder = builder.protocol(Protocol.HTTP_1_1); builder = builder.method(Method.CONNECT); if (proxyHeaders != null && proxyHeaders.size() > 0) { for (Map.Entry<String, String> entry : proxyHeaders.entrySet()) { builder.header(entry.getKey(), entry.getValue()); } } builder = builder.header(Header.Host, requestURI.getHost()); builder = builder.header(Header.ProxyConnection, "keep-alive"); builder = builder.header(Header.Connection, "keep-alive"); ctx.write(HttpContent.builder(builder.build()).build()); ctx.flush(null); } else { ctx.write(getHttpContent(upgradeRequest)); } // call the next filter in the chain return ctx.getInvokeAction(); }
private NextAction sendRequest(FilterChainContext ctx, UpgradeRequest upgradeRequest) { HttpRequestPacket.Builder builder = HttpRequestPacket.builder(); if (proxy && !PROXY_CONNECTED.get(ctx.getConnection())) { UPGRADE_REQUEST.set(ctx.getConnection(), upgradeRequest); URI requestURI = upgradeRequest.getRequestURI(); final int requestPort = Utils.getWsPort(requestURI); builder = builder.uri(String.format("%s:%d", requestURI.getHost(), requestPort)); builder = builder.protocol(Protocol.HTTP_1_1); builder = builder.method(Method.CONNECT); if (proxyHeaders != null && proxyHeaders.size() > 0) { for (Map.Entry<String, String> entry : proxyHeaders.entrySet()) { builder.header(entry.getKey(), entry.getValue()); } } builder = builder.header(Header.Host, requestURI.getHost()); builder = builder.header(Header.ProxyConnection, "keep-alive"); builder = builder.header(Header.Connection, "keep-alive"); ctx.write(HttpContent.builder(builder.build()).build()); ctx.flush(null); } else { ctx.write(getHttpContent(upgradeRequest)); } // call the next filter in the chain return ctx.getInvokeAction(); }