static CharSequence websocketHostValue(URI wsURL) { int port = wsURL.getPort(); if (port == -1) { return wsURL.getHost(); } String host = wsURL.getHost(); if (port == HttpScheme.HTTP.port()) { return HttpScheme.HTTP.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } if (port == HttpScheme.HTTPS.port()) { return HttpScheme.HTTPS.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WSS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return NetUtil.toSocketAddressString(host, port); }
static CharSequence websocketOriginValue(URI wsURL) { String scheme = wsURL.getScheme(); final String schemePrefix; int port = wsURL.getPort(); final int defaultPort; if (WebSocketScheme.WSS.name().contentEquals(scheme) || HttpScheme.HTTPS.name().contentEquals(scheme) || (scheme == null && port == WebSocketScheme.WSS.port())) { schemePrefix = HTTPS_SCHEME_PREFIX; defaultPort = WebSocketScheme.WSS.port(); } else { schemePrefix = HTTP_SCHEME_PREFIX; defaultPort = WebSocketScheme.WS.port(); } // Convert uri-host to lower case (by RFC 6454, chapter 4 "Origin of a URI") String host = wsURL.getHost().toLowerCase(Locale.US); if (port != defaultPort && port != -1) { // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return schemePrefix + NetUtil.toSocketAddressString(host, port); } return schemePrefix + host; } }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. if (LOGGER.isWarnEnabled()) { LOGGER.warn("Directly talking: {} (no upgrade was attempted) from {}", msg.protocolVersion(), NetUtil.toSocketAddressString(ch.remoteAddress())); } ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); // 不需要了 pipeline.addAfter(bizGroup, thisCtx.name(), "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); pipeline.replace(this, "HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); // HttpServerUpgradeHandler -> HttpServerCodec -> HttpObjectAggregator -> Http1ChannelHandler, ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } });
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. if (LOGGER.isWarnEnabled()) { LOGGER.warn("Directly talking: {} (no upgrade was attempted) from {}", msg.protocolVersion(), NetUtil.toSocketAddressString(ch.remoteAddress())); } ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); // 不需要了 pipeline.addAfter(bizGroup, thisCtx.name(), "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); pipeline.replace(this, "HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); // HttpServerUpgradeHandler -> HttpServerCodec -> HttpObjectAggregator -> Http1ChannelHandler, ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } });
@SuppressWarnings("unchecked") static String toSocketAddressStringWithoutDefaultPort( SocketAddress address, boolean secure) { if (!(address instanceof InetSocketAddress)) { throw new IllegalStateException("Only support InetSocketAddress representation"); } String addressString = NetUtil.toSocketAddressString((InetSocketAddress)address); if (secure) { if (addressString.endsWith(":443")) { addressString = addressString.substring(0, addressString.length() - 4); } } else { if (addressString.endsWith(":80")) { addressString = addressString.substring(0, addressString.length() - 3); } } return addressString; }
@SuppressWarnings("unchecked") static String toSocketAddressStringWithoutDefaultPort( SocketAddress address, boolean secure) { if (!(address instanceof InetSocketAddress)) { throw new IllegalStateException("Only support InetSocketAddress representation"); } String addressString = NetUtil.toSocketAddressString((InetSocketAddress)address); if (secure) { if (addressString.endsWith(":443")) { addressString = addressString.substring(0, addressString.length() - 4); } } else { if (addressString.endsWith(":80")) { addressString = addressString.substring(0, addressString.length() - 3); } } return addressString; }
return scheme + NetUtil.toSocketAddressString((InetSocketAddress) remote) + url;
static CharSequence websocketHostValue(URI wsURL) { int port = wsURL.getPort(); if (port == -1) { return wsURL.getHost(); } String host = wsURL.getHost(); if (port == HttpScheme.HTTP.port()) { return HttpScheme.HTTP.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } if (port == HttpScheme.HTTPS.port()) { return HttpScheme.HTTPS.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WSS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return NetUtil.toSocketAddressString(host, port); }
static CharSequence websocketHostValue(URI wsURL) { int port = wsURL.getPort(); if (port == -1) { return wsURL.getHost(); } String host = wsURL.getHost(); if (port == HttpScheme.HTTP.port()) { return HttpScheme.HTTP.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } if (port == HttpScheme.HTTPS.port()) { return HttpScheme.HTTPS.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WSS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return NetUtil.toSocketAddressString(host, port); }
static CharSequence websocketHostValue(URI wsURL) { int port = wsURL.getPort(); if (port == -1) { return wsURL.getHost(); } String host = wsURL.getHost(); if (port == HttpScheme.HTTP.port()) { return HttpScheme.HTTP.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } if (port == HttpScheme.HTTPS.port()) { return HttpScheme.HTTPS.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WSS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return NetUtil.toSocketAddressString(host, port); }
static CharSequence websocketHostValue(URI wsURL) { int port = wsURL.getPort(); if (port == -1) { return wsURL.getHost(); } String host = wsURL.getHost(); if (port == HttpScheme.HTTP.port()) { return HttpScheme.HTTP.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } if (port == HttpScheme.HTTPS.port()) { return HttpScheme.HTTPS.name().contentEquals(wsURL.getScheme()) || WebSocketScheme.WSS.name().contentEquals(wsURL.getScheme()) ? host : NetUtil.toSocketAddressString(host, port); } // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return NetUtil.toSocketAddressString(host, port); }
static CharSequence websocketOriginValue(URI wsURL) { String scheme = wsURL.getScheme(); final String schemePrefix; int port = wsURL.getPort(); final int defaultPort; if (WebSocketScheme.WSS.name().contentEquals(scheme) || HttpScheme.HTTPS.name().contentEquals(scheme) || (scheme == null && port == WebSocketScheme.WSS.port())) { schemePrefix = HTTPS_SCHEME_PREFIX; defaultPort = WebSocketScheme.WSS.port(); } else { schemePrefix = HTTP_SCHEME_PREFIX; defaultPort = WebSocketScheme.WS.port(); } // Convert uri-host to lower case (by RFC 6454, chapter 4 "Origin of a URI") String host = wsURL.getHost().toLowerCase(Locale.US); if (port != defaultPort && port != -1) { // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return schemePrefix + NetUtil.toSocketAddressString(host, port); } return schemePrefix + host; } }
static CharSequence websocketOriginValue(URI wsURL) { String scheme = wsURL.getScheme(); final String schemePrefix; int port = wsURL.getPort(); final int defaultPort; if (WebSocketScheme.WSS.name().contentEquals(scheme) || HttpScheme.HTTPS.name().contentEquals(scheme) || (scheme == null && port == WebSocketScheme.WSS.port())) { schemePrefix = HTTPS_SCHEME_PREFIX; defaultPort = WebSocketScheme.WSS.port(); } else { schemePrefix = HTTP_SCHEME_PREFIX; defaultPort = WebSocketScheme.WS.port(); } // Convert uri-host to lower case (by RFC 6454, chapter 4 "Origin of a URI") String host = wsURL.getHost().toLowerCase(Locale.US); if (port != defaultPort && port != -1) { // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return schemePrefix + NetUtil.toSocketAddressString(host, port); } return schemePrefix + host; } }
static CharSequence websocketOriginValue(URI wsURL) { String scheme = wsURL.getScheme(); final String schemePrefix; int port = wsURL.getPort(); final int defaultPort; if (WebSocketScheme.WSS.name().contentEquals(scheme) || HttpScheme.HTTPS.name().contentEquals(scheme) || (scheme == null && port == WebSocketScheme.WSS.port())) { schemePrefix = HTTPS_SCHEME_PREFIX; defaultPort = WebSocketScheme.WSS.port(); } else { schemePrefix = HTTP_SCHEME_PREFIX; defaultPort = WebSocketScheme.WS.port(); } // Convert uri-host to lower case (by RFC 6454, chapter 4 "Origin of a URI") String host = wsURL.getHost().toLowerCase(Locale.US); if (port != defaultPort && port != -1) { // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return schemePrefix + NetUtil.toSocketAddressString(host, port); } return schemePrefix + host; } }
static CharSequence websocketOriginValue(URI wsURL) { String scheme = wsURL.getScheme(); final String schemePrefix; int port = wsURL.getPort(); final int defaultPort; if (WebSocketScheme.WSS.name().contentEquals(scheme) || HttpScheme.HTTPS.name().contentEquals(scheme) || (scheme == null && port == WebSocketScheme.WSS.port())) { schemePrefix = HTTPS_SCHEME_PREFIX; defaultPort = WebSocketScheme.WSS.port(); } else { schemePrefix = HTTP_SCHEME_PREFIX; defaultPort = WebSocketScheme.WS.port(); } // Convert uri-host to lower case (by RFC 6454, chapter 4 "Origin of a URI") String host = wsURL.getHost().toLowerCase(Locale.US); if (port != defaultPort && port != -1) { // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 return schemePrefix + NetUtil.toSocketAddressString(host, port); } return schemePrefix + host; } }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. if (LOGGER.isWarnEnabled()) { LOGGER.warn("Directly talking: {} (no upgrade was attempted) from {}", msg.protocolVersion(), NetUtil.toSocketAddressString(ch.remoteAddress())); } ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); // 不需要了 pipeline.addAfter(bizGroup, thisCtx.name(), "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); pipeline.replace(this, "HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); // HttpServerUpgradeHandler -> HttpServerCodec -> HttpObjectAggregator -> Http1ChannelHandler, ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } });