private String getNextProtocol(IoSession session) { if (session instanceof BridgeSession) { ResourceAddress localAddress = ((BridgeSession) session).getLocalAddress(); return localAddress.getOption(NEXT_PROTOCOL); } return null; }
@SuppressWarnings("unchecked") @Override public <T> T getOption(ResourceOption<T> key) { if (ResourceAddress.TRANSPORT_URI.equals(key) || ResourceAddress.TRANSPORT.equals(key) || ResourceAddress.TRANSPORTED_URI.equals(key)) { return null; } Object override = optionOverrides.get(key); return override != null ? (T) override : httpSession.getRemoteAddress().getOption(key); } }
static boolean elevateEmulatedRequestRequired(IoSession session) { if ("httpxe/1.1".equals(BridgeSession.LOCAL_ADDRESS.get(session).getOption(NEXT_PROTOCOL))) { DefaultHttpSession httpSession = (DefaultHttpSession) session; // XDR needs to explicitly envelope the request, so we must not treat this as requiring implicit elevation return !isExplicitEnvelopedContentType(httpSession) && isLegacyClient(httpSession) && (isEmulatedWebSocketRequest(httpSession) || isRevalidateWebSocketRequest(httpSession) || isApiRequest(httpSession)); } return false; }
private IoHandler selectHandler(ResourceAddress address) { ResourceAddress httpTransport = address.getTransport(); String httpNextProtocol = httpTransport.getOption(NEXT_PROTOCOL); if ( PROTOCOL_NAME_WEB_SOCKET_RFC6455.equals(httpNextProtocol)) { return wsnHttpRFC6455BridgeHandler; } else if ( PROTOCOL_NAME_WEB_SOCKET_DRAFT.equals(httpNextProtocol)) { return wsnHttpDelegatingBridgeHandler; } return null; }
public static boolean writeExtraEmptyPacketRequired(IoSession session) { if ("x-kaazing-handshake".equals(BridgeSession.LOCAL_ADDRESS.get(session).getOption(NEXT_PROTOCOL))) { WsnSession wsnSession = (WsnSession) session; String query = wsnSession.getParentHttpRequestURI().getQuery(); return (query != null) && (query.contains(".kl=Y")||query.contains(".kv=10.05")); } return false; } }
@Override public String toString() { String nextProtocol = bindAddress.getOption(NEXT_PROTOCOL); nextProtocol = (nextProtocol == null ? "" : " "+nextProtocol); return format("([%s%s],0x%x,0x%x,#%d)", bindAddress.getResource(), nextProtocol, identityHashCode(handler), identityHashCode(initializer), referenceCount()); }
@Override public void initializeSession(IoSession session, T future) { if ( theCreateInitializer != null ) { theCreateInitializer.initializeSession(session, future); } // Store the next over-the-top of-websocket protocols the server supports for this address on session. SUPPORTED_PROTOCOLS.set(session, address.getOption(WsResourceAddress.SUPPORTED_PROTOCOLS)); } };
protected void resolve(String oldPath, String newPath, ResourceOptions newOptions) { ResourceAddress transport = getOption(TRANSPORT); if (transport != null) { newOptions.setOption(TRANSPORT, transport.resolve(oldPath, newPath)); } ResourceAddress alternate = getOption(ALTERNATE); if (alternate != null) { newOptions.setOption(ALTERNATE, alternate.resolve(oldPath, newPath)); } }
@Override protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { if (logger.isTraceEnabled()) { logger.trace(format("unbinding: '%s' %s", address.getExternalURI(), address.getOption(NEXT_PROTOCOL))); } ResourceAddress transport = address.getTransport(); BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transport); return acceptor.unbind(transport); }
public boolean isChunkingNecessary() { // if there is no content length specified, is chunking necessary? // well, yes usually. but if you are a wrapped response at the httpxe layer and a legacy client, then no. // why? because the content is length-encoded already. ResourceAddress address = getLocalAddress().getTransport(); return address != null && ( ! "httpxe/1.1".equals(address.getOption(ResourceAddress.NEXT_PROTOCOL)) && ! conditionallyWrappedResponsesRequired(this)); }
@Override protected void registerAcceptFilters(ResourceAddress boundAddress, IoSession session) { Integer align = boundAddress.getOption(PADDING_ALIGNMENT); if (align > 0) { session.getFilterChain().addFirst("udp.padding.alignment", new UdpAlignFilter(logger, align, session)); } }
@Override protected void registerConnectFilters(ResourceAddress address, IoSession session) { int align = address.getOption(UdpResourceAddress.PADDING_ALIGNMENT); if (align > 0) { session.getFilterChain().addFirst("udp.padding.alignment", new UdpAlignFilter(logger, align, session)); } }
public static void setServerHeader(DefaultHttpSession httpSession, HttpResponseMessage httpResponse) { if (httpSession != null) { ResourceAddress address = httpSession.getLocalAddress(); boolean serverHeaderEnabled = address.getOption(HttpResourceAddress.SERVER_HEADER_ENABLED); if (serverHeaderEnabled && !httpResponse.hasHeader("Server")) { httpResponse.setHeader("Server", "Kaazing Gateway"); } } } }
private boolean deferOriginSecurityToHttpxe(IoSessionEx session, HttpRequestMessage httpRequest) { ResourceAddress resourceAddress = BridgeSession.LOCAL_ADDRESS.get(session); String nextProtocol = resourceAddress.getOption(NEXT_PROTOCOL); return "http/1.1".equals(nextProtocol) && isLegacyClient(httpRequest) && (isEmulatedWebSocketRequest(httpRequest) || isRevalidateWebSocketRequest(httpRequest)); }
public static void setDateHeader(IoSession session, HttpResponseMessage response) { DefaultHttpSession httpSession = HttpAcceptor.SESSION_KEY.get(session); if(httpSession != null) { ResourceAddress address = httpSession.getLocalAddress(); boolean dateHeaderEnabled = address.getOption(HttpResourceAddress.DATE_HEADER_ENABLED); if(dateHeaderEnabled && !response.hasHeader("Date")) { response.setHeader(HttpHeaders.HEADER_DATE, formatDateHeader(System.currentTimeMillis())); } } }
public ResourceAddress newResourceAddress(ResourceAddress uriAddress, ResourceAddress transportAddress) { ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT, transportAddress); options.setOption(NEXT_PROTOCOL, uriAddress.getOption(NEXT_PROTOCOL)); return newResourceAddress(uriToString(uriAddress.getResource()), options); }
private void addSession0(IoSessionEx wsebSession) { if (ALREADY_TRACKED.get(wsebSession, false)) { // Expected for downstream reconnects return; } IoSessionEx transportSession = ((WsebSession)wsebSession).getTransportSession(); ALREADY_TRACKED.set(wsebSession, true); idleTracker.addSession(transportSession); WsCheckAliveFilter.addIfFeatureEnabled(transportSession.getFilterChain(), CHECK_ALIVE_FILTER, ((WsebSession) wsebSession).getLocalAddress().getOption(INACTIVITY_TIMEOUT), wsebSession, logger); }
private ResourceAddress getCandidateResourceAddress(IoSessionEx session) { // Build candidate address from session final ResourceAddress candidateTransportAddress = REMOTE_ADDRESS.get(session); URI candidateURI = candidateTransportAddress.getOption(TRANSPORTED_URI); ResourceOptions candidateOptions = ResourceOptions.FACTORY.newResourceOptions(); candidateOptions.setOption(NEXT_PROTOCOL, NEXT_PROTOCOL_KEY.get(session)); candidateOptions.setOption(TRANSPORT, candidateTransportAddress); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(candidateURI), candidateOptions); }
private void bindApiPath(ResourceAddress address) { ResourceAddress apiHttpAddress = createApiHttpAddress(address.getTransport()); bridgeServiceFactory.newBridgeAcceptor(apiHttpAddress).bind(apiHttpAddress, WsAcceptor.API_PATH_HANDLER, null); ResourceAddress apiHttpxeAddress = address.getTransport().getOption(ALTERNATE); if (apiHttpxeAddress != null) { apiHttpxeAddress = createApiHttpxeAddress(apiHttpxeAddress); bridgeServiceFactory.newBridgeAcceptor(apiHttpxeAddress).bind(apiHttpxeAddress, WsAcceptor.API_PATH_HANDLER, null); } }
private void unbindApiPath(ResourceAddress address) { ResourceAddress apiHttpAddress = createApiHttpAddress(address.getTransport()); bridgeServiceFactory.newBridgeAcceptor(apiHttpAddress).unbind(apiHttpAddress); ResourceAddress apiHttpxeAddress = address.getTransport().getOption(ALTERNATE); if (apiHttpxeAddress != null) { apiHttpxeAddress = createApiHttpxeAddress(apiHttpxeAddress); bridgeServiceFactory.newBridgeAcceptor(apiHttpxeAddress).unbind(apiHttpxeAddress); } }