Java Code Examples for io.undertow.websockets.spi.WebSocketHttpExchange#setResponseHeader()
The following examples show how to use
io.undertow.websockets.spi.WebSocketHttpExchange#setResponseHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Hybi13Handshake.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void handshakeInternal(final WebSocketHttpExchange exchange) { String origin = exchange.getRequestHeader(Headers.ORIGIN_STRING); if (origin != null) { exchange.setResponseHeader(Headers.ORIGIN_STRING, origin); } selectSubprotocol(exchange); selectExtensions(exchange); exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_LOCATION_STRING, getWebSocketLocation(exchange)); final String key = exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_KEY_STRING); try { final String solution = solve(key); exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_ACCEPT_STRING, solution); performUpgrade(exchange); } catch (NoSuchAlgorithmException e) { IoUtils.safeClose(exchange); exchange.endExchange(); return; } }
Example 2
Source File: Hybi07Handshake.java From lams with GNU General Public License v2.0 | 6 votes |
protected void handshakeInternal(final WebSocketHttpExchange exchange) { String origin = exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_ORIGIN_STRING); if (origin != null) { exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_ORIGIN_STRING, origin); } selectSubprotocol(exchange); selectExtensions(exchange); exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_LOCATION_STRING, getWebSocketLocation(exchange)); final String key = exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_KEY_STRING); try { final String solution = solve(key); exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_ACCEPT_STRING, solution); performUpgrade(exchange); } catch (NoSuchAlgorithmException e) { IoUtils.safeClose(exchange); exchange.endExchange(); return; } }
Example 3
Source File: Handshake.java From lams with GNU General Public License v2.0 | 5 votes |
/** * convenience method to perform the upgrade */ protected final void performUpgrade(final WebSocketHttpExchange exchange, final byte[] data) { exchange.setResponseHeader(Headers.CONTENT_LENGTH_STRING, String.valueOf(data.length)); exchange.setResponseHeader(Headers.UPGRADE_STRING, "WebSocket"); exchange.setResponseHeader(Headers.CONNECTION_STRING, "Upgrade"); upgradeChannel(exchange, data); }
Example 4
Source File: Handshake.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Selects the first matching supported sub protocol and add it the the headers of the exchange. * */ protected final void selectSubprotocol(final WebSocketHttpExchange exchange) { String requestedSubprotocols = exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_PROTOCOL_STRING); if (requestedSubprotocols == null) { return; } String[] requestedSubprotocolArray = PATTERN.split(requestedSubprotocols); String subProtocol = supportedSubprotols(requestedSubprotocolArray); if (subProtocol != null && !subProtocol.isEmpty()) { exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_PROTOCOL_STRING, subProtocol); } }
Example 5
Source File: Handshake.java From lams with GNU General Public License v2.0 | 5 votes |
protected final void selectExtensions(final WebSocketHttpExchange exchange) { List<WebSocketExtension> requestedExtensions = WebSocketExtension.parse(exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_EXTENSIONS_STRING)); List<WebSocketExtension> extensions = selectedExtension(requestedExtensions); if (extensions != null && !extensions.isEmpty()) { exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_EXTENSIONS_STRING, WebSocketExtension.toExtensionHeader(extensions)); } }