Refine search
protected boolean verifySecureToken(final FullHttpRequest request, final PushConnection conn) { final String secureToken = request.headers().get(SECURE_TOKEN_HEADER_NAME); if (Strings.isNullOrEmpty(secureToken)) { // caller is not asking to verify secure token return true; } return secureToken.equals(conn.getSecureToken()); }
private int parseTimeout() { String timeout = request.headers().get(Constants.HTTP_HEAD_READ_TIMEOUT); if (timeout != null) { request.headers().remove(Constants.HTTP_HEAD_READ_TIMEOUT); Integer integer = Ints.tryParse(timeout); if (integer != null && integer > 0) { return integer; } } return TIMEOUT; }
protected final Cookies parseCookies(FullHttpRequest req) { final Cookies cookies = new Cookies(); final String cookieStr = req.headers().get(HttpHeaderNames.COOKIE); if (!Strings.isNullOrEmpty(cookieStr)) { final Set<Cookie> decoded = CookieDecoder.decode(cookieStr, false); decoded.forEach(cookie -> cookies.add(cookie)); } return cookies; }
@Override public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception { // Idle timeout if (evt instanceof IdleStateEvent) { log.debug("idle timeout: {}", ctx); ctx.close(); } else if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) { // Write an HTTP/2 response to the upgrade request FullHttpRequest req = ((HttpServerUpgradeHandler.UpgradeEvent) evt).upgradeRequest(); req.headers().set(STREAM_ID, req.headers().get(STREAM_ID, "1")); channelRead0(ctx, req); } else { super.userEventTriggered(ctx, evt); } }
protected boolean verifySecureToken(final FullHttpRequest request, final PushConnection conn) { final String secureToken = request.headers().get(SECURE_TOKEN_HEADER_NAME); if (Strings.isNullOrEmpty(secureToken)) { // caller is not asking to verify secure token return true; } return secureToken.equals(conn.getSecureToken()); }
public User getUserFromCookie(FullHttpRequest request) { String cookieString = request.headers().get(HttpHeaderNames.COOKIE); if (cookieString != null) { Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieString); if (!cookies.isEmpty()) { for (Cookie cookie : cookies) { if (isValid(cookie)) { String token = cookie.value(); return httpSession.get(token); } } } } return null; }
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { FullHttpRequest request = (FullHttpRequest) msg; DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, request.headers().get("From")); if (deviceSession != null) { sendResponse(channel, HttpResponseStatus.OK); } else { sendResponse(channel, HttpResponseStatus.BAD_REQUEST); } return null; }
@Override public void preRequest(FullHttpRequest request) { String cookieHeader = request.headers().get(HttpHeaders.Names.COOKIE); boolean authenticated = false; if (cookieHeader != null) { String[] cookies = cookieHeader.split(";"); for (String cookie : cookies) { String[] cookieArr = cookie.split("="); if (AUTH_COOKIE_KEY.equals(cookieArr[0].trim())) { if (cookieArr.length == 2 && cookieArr[1].equals(token)) { authenticated = true; } } } } String auth = request.headers().get(HttpHeaders.Names.AUTHORIZATION); if (!authenticated && auth != null) { String[] authArr = auth.split(" "); if (authArr.length == 2 && authArr[0].equals(ProxyConfig.getInstance().getConfigAdminUsername()) && authArr[1].equals(ProxyConfig.getInstance().getConfigAdminPassword())) { authenticated = true; } } if (!request.getUri().equals("/login") && !authenticated) { throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED); } logger.info("handle request for api {}", request.getUri()); } });
private void setBody(HttpRequest httpRequest, FullHttpRequest fullHttpRequest) { if (fullHttpRequest.content() != null && fullHttpRequest.content().readableBytes() > 0) { byte[] bodyBytes = new byte[fullHttpRequest.content().readableBytes()]; fullHttpRequest.content().readBytes(bodyBytes); if (bodyBytes.length > 0) { if (ContentTypeMapper.isBinary(fullHttpRequest.headers().get(CONTENT_TYPE))) { httpRequest.withBody(new BinaryBody(bodyBytes)); } else { Charset requestCharset = ContentTypeMapper.getCharsetFromContentTypeHeader(fullHttpRequest.headers().get(CONTENT_TYPE)); httpRequest.withBody(new StringBody(new String(bodyBytes, requestCharset), DEFAULT_HTTP_CHARACTER_SET.equals(requestCharset) ? null : requestCharset)); } } } } }
if (!req.headers().containsValue(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE, true) || !HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(req.headers().get(HttpHeaderNames.UPGRADE))) { throw new WebSocketHandshakeException("not a WebSocket handshake request: missing upgrade"); boolean isHixie76 = req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) && req.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2); res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, req.headers().get(HttpHeaderNames.ORIGIN)); res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_LOCATION, uri()); String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols); String key1 = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY1); String key2 = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY2); int a = (int) (Long.parseLong(BEGINNING_DIGIT.matcher(key1).replaceAll("")) / BEGINNING_SPACE.matcher(key1).replaceAll("").length()); } else { res.headers().add(HttpHeaderNames.WEBSOCKET_ORIGIN, req.headers().get(HttpHeaderNames.ORIGIN)); res.headers().add(HttpHeaderNames.WEBSOCKET_LOCATION, uri()); String protocol = req.headers().get(HttpHeaderNames.WEBSOCKET_PROTOCOL); if (protocol != null) { res.headers().add(HttpHeaderNames.WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
private void parseHeader(FullHttpRequest httpRequest, SofaRequest sofaRequest) { HttpHeaders headers = httpRequest.headers(); // 获取序列化类型 byte serializeType; if (httpRequest.method() == HttpMethod.GET) { serializeType = 0; } else { String codeName = headers.get(RemotingConstants.HEAD_SERIALIZE_TYPE); if (codeName != null) { serializeType = HttpTransportUtils.getSerializeTypeByName(codeName); } else { String contentType = headers.get(HttpHeaderNames.CONTENT_TYPE); serializeType = HttpTransportUtils.getSerializeTypeByContentType(contentType); } } sofaRequest.setSerializeType(serializeType); // 服务端应用 sofaRequest.setTargetAppName(headers.get(RemotingConstants.HEAD_TARGET_APP)); }
private void parseHeader(FullHttpRequest httpRequest, SofaRequest sofaRequest) { HttpHeaders headers = httpRequest.headers(); // 获取序列化类型 byte serializeType; if (httpRequest.method() == HttpMethod.GET) { serializeType = 0; } else { String codeName = headers.get(RemotingConstants.HEAD_SERIALIZE_TYPE); if (codeName != null) { serializeType = HttpTransportUtils.getSerializeTypeByName(codeName); } else { String contentType = headers.get(HttpHeaderNames.CONTENT_TYPE); serializeType = HttpTransportUtils.getSerializeTypeByContentType(contentType); } } sofaRequest.setSerializeType(serializeType); // 服务端应用 sofaRequest.setTargetAppName(headers.get(RemotingConstants.HEAD_TARGET_APP)); }
protected final Cookies parseCookies(FullHttpRequest req) { final Cookies cookies = new Cookies(); final String cookieStr = req.headers().get(HttpHeaderNames.COOKIE); if (!Strings.isNullOrEmpty(cookieStr)) { final Set<Cookie> decoded = CookieDecoder.decode(cookieStr, false); decoded.forEach(cookie -> cookies.add(cookie)); } return cookies; }
private void upgradeChannel(final ChannelHandlerContext ctx, FullHttpRequest httpRequest) { handshaker = new WebSocketServerHandshakerFactory( "ws://" + httpRequest.headers().get(HOST) + UPGRADE_CHANNEL_FOR_UI_WEB_SOCKET_URI, null, true, Integer.MAX_VALUE ).newHandshaker(httpRequest); if (handshaker == null) { WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); } else { handshaker.handshake( ctx.channel(), httpRequest, new DefaultHttpHeaders(), ctx.channel().newPromise() ).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { clientRegistry.put(ctx, request()); } }); } }
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY); if (key == null) { throw new WebSocketHandshakeException("not a WebSocket request: missing key"); res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept); String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY); if (key == null) { throw new WebSocketHandshakeException("not a WebSocket request: missing key"); res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept); String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols);
CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY); if (key == null) { throw new WebSocketHandshakeException("not a WebSocket request: missing key"); res.headers().add(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept); String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL); if (subprotocols != null) { String selectedSubprotocol = selectSubprotocol(subprotocols);