public HandShake(URI url) { builder = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_1) .method(Method.GET) .header(Header.Connection, "Upgrade") .upgrade("WebSocket"); resourcePath = url.getPath(); if ("".equals(resourcePath)) { resourcePath = "/"; } if (url.getQuery() != null) { resourcePath += "?" + url.getQuery(); } serverHostName = url.getHost(); secure = "wss://".equals(url.getScheme()); port = url.getPort(); final StringBuilder sb = new StringBuilder(32) .append(getScheme()).append("://").append(url.getHost()); origin = appendPort(sb).toString().toLowerCase(Locale.ENGLISH); buildLocation(); }
public HandShake(URI url) { builder = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_1) .method(Method.GET) .header(Header.Connection, "Upgrade") .upgrade("WebSocket"); resourcePath = url.getPath(); if ("".equals(resourcePath)) { resourcePath = "/"; } if (url.getQuery() != null) { resourcePath += "?" + url.getQuery(); } serverHostName = url.getHost(); secure = "wss://".equals(url.getScheme()); port = url.getPort(); final StringBuilder sb = new StringBuilder(32) .append(getScheme()).append("://").append(url.getHost()); origin = appendPort(sb).toString().toLowerCase(Locale.ENGLISH); buildLocation(); }
public HandShake(URI url) { builder = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_1) .method(Method.GET) .header(Header.Connection, "Upgrade") .upgrade("WebSocket"); resourcePath = url.getPath(); if ("".equals(resourcePath)) { resourcePath = "/"; } if (url.getQuery() != null) { resourcePath += "?" + url.getQuery(); } serverHostName = url.getHost(); secure = "wss://".equals(url.getScheme()); port = url.getPort(); final StringBuilder sb = new StringBuilder(32) .append(getScheme()).append("://").append(url.getHost()); origin = appendPort(sb).toString().toLowerCase(Locale.ENGLISH); buildLocation(); }
builder = builder.protocol(Protocol.HTTP_1_1); builder = builder.method(Method.CONNECT); 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);
builder.header(headerEntry.getKey(), finalHeaderValue.toString());
builder.header(headerEntry.getKey(), finalHeaderValue.toString());
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(); }
/** * The method is called, when a client connection gets connected to a web * server. * When this method gets called by a framework - it means that client connection * has been established and we can send HTTP request to the web server. * * @param ctx Client connect processing context * * @return {@link NextAction} * @throws IOException */ @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { // Build the HttpRequestPacket, which will be sent to a server // We construct HTTP request version 1.1 and specifying the URL of the // resource we want to download final HttpRequestPacket httpRequest = HttpRequestPacket.builder().method("GET") .uri(resourcePath).protocol(Protocol.HTTP_1_1) .header("Host", uri.getHost()).build(); logger.log(Level.INFO, "Connected... Sending the request: {0}", httpRequest); // Write the request asynchronously ctx.write(httpRequest); // Return the stop action, which means we don't expect next filter to process // connect event return ctx.getStopAction(); }
public HandShake(URI url) { builder = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_1) .method(Method.GET) .header(Header.Connection, "Upgrade") .upgrade("WebSocket"); resourcePath = url.getPath(); if ("".equals(resourcePath)) { resourcePath = "/"; } if (url.getQuery() != null) { resourcePath += "?" + url.getQuery(); } serverHostName = url.getHost(); secure = "wss://".equals(url.getScheme()); port = url.getPort(); final StringBuilder sb = new StringBuilder(32) .append(getScheme()).append("://").append(url.getHost()); origin = appendPort(sb).toString().toLowerCase(Locale.ENGLISH); buildLocation(); }
public HandShake(URI url) { builder = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_1) .method(Method.GET) .header(Header.Connection, "Upgrade") .upgrade("WebSocket"); resourcePath = url.getPath(); if ("".equals(resourcePath)) { resourcePath = "/"; } if (url.getQuery() != null) { resourcePath += "?" + url.getQuery(); } serverHostName = url.getHost(); secure = "wss://".equals(url.getScheme()); port = url.getPort(); final StringBuilder sb = new StringBuilder(32) .append(getScheme()).append("://").append(url.getHost()); origin = appendPort(sb).toString().toLowerCase(Locale.ENGLISH); buildLocation(); }
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(); }
/** * Create HttpContent (Grizzly request representation) from {@link WebSocketRequest}. * * @param request original request. * @return Grizzly representation of provided request. */ private HttpContent getHttpContent(WebSocketRequest request) { HttpRequestPacket.Builder builder = HttpRequestPacket.builder(); builder = builder.protocol(Protocol.HTTP_1_1); builder = builder.method(Method.GET); builder = builder.uri(request.getRequestPath()); for (Map.Entry<String, List<String>> headerEntry : request.getHeaders().entrySet()) { StringBuilder finalHeaderValue = new StringBuilder(); for(String headerValue : headerEntry.getValue()) { if(finalHeaderValue.length() != 0) { finalHeaderValue.append(", "); } finalHeaderValue.append(headerValue); } builder.header(headerEntry.getKey(), finalHeaderValue.toString()); } return HttpContent.builder(builder.build()).build(); }
public HandShake(URI url) { builder = HttpRequestPacket.builder() .protocol(Protocol.HTTP_1_1) .method(Method.GET) .header(Header.Connection, "Upgrade") .upgrade("WebSocket"); resourcePath = url.getPath(); if ("".equals(resourcePath)) { resourcePath = "/"; } if (url.getQuery() != null) { resourcePath += "?" + url.getQuery(); } serverHostName = url.getHost(); secure = "wss://".equals(url.getScheme()); port = url.getPort(); final StringBuilder sb = new StringBuilder(32) .append(getScheme()).append("://").append(url.getHost()); origin = appendPort(sb).toString().toLowerCase(Locale.ENGLISH); buildLocation(); }
public HttpContent composeHeaders() { String host = getServerHostName(); if (port != -1 && port != 80 && port != 443) { host += ":" + getPort(); } builder.uri(getResourcePath()) .header(Header.Host, host); if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } else { builder.removeHeader(Constants.SEC_WS_EXTENSIONS_HEADER); } if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } return HttpContent.builder(builder.build()).build(); }
public HttpContent composeHeaders() { String host = getServerHostName(); if (port != -1 && port != 80 && port != 443) { host += ":" + getPort(); } builder.uri(getResourcePath()) .header(Header.Host, host); if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } else { builder.removeHeader(Constants.SEC_WS_EXTENSIONS_HEADER); } if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } return HttpContent.builder(builder.build()).build(); }
public HttpContent composeHeaders() { String host = getServerHostName(); if (port != -1 && port != 80 && port != 443) { host += ":" + getPort(); } builder.uri(getResourcePath()) .header(Header.Host, host); if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } else { builder.removeHeader(Constants.SEC_WS_EXTENSIONS_HEADER); } if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } return HttpContent.builder(builder.build()).build(); }
public HttpContent composeHeaders() { String host = getServerHostName(); if (port != -1 && port != 80 && port != 443) { host += ":" + getPort(); } builder.uri(getResourcePath()) .header(Header.Host, host); if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } else { builder.removeHeader(Constants.SEC_WS_EXTENSIONS_HEADER); } if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } return HttpContent.builder(builder.build()).build(); }
public HttpContent composeHeaders() { String host = getServerHostName(); if (port != -1 && port != 80 && port != 443) { host += ":" + getPort(); } builder.uri(getResourcePath()) .header(Header.Host, host); if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } else { builder.removeHeader(Constants.SEC_WS_EXTENSIONS_HEADER); } if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } return HttpContent.builder(builder.build()).build(); }
public HttpContent composeHeaders() { String host = getServerHostName(); if (port != -1 && port != 80 && port != 443) { host += ":" + getPort(); } builder.uri(getResourcePath()) .header(Header.Host, host); if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } else { builder.removeHeader(Constants.SEC_WS_EXTENSIONS_HEADER); } if (!getSubProtocol().isEmpty()) { builder.header(Constants.SEC_WS_PROTOCOL_HEADER, join(getSubProtocol())); } return HttpContent.builder(builder.build()).build(); }