io.undertow.websockets.spi.WebSocketHttpExchange.getRequestHeader()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中io.undertow.websockets.spi.WebSocketHttpExchange.getRequestHeader()方法的一些代码示例,展示了WebSocketHttpExchange.getRequestHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocketHttpExchange.getRequestHeader()方法的具体详情如下:
包路径:io.undertow.websockets.spi.WebSocketHttpExchange
类名称:WebSocketHttpExchange
方法名:getRequestHeader

WebSocketHttpExchange.getRequestHeader介绍

[英]gets the first request header with the specified name
[中]获取具有指定名称的第一个请求标头

代码示例

代码示例来源:origin: wildfly/wildfly

@Override
public boolean matches(final WebSocketHttpExchange exchange) {
  if (exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_KEY_STRING) != null &&
      exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_VERSION_STRING) != null) {
    return exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_VERSION_STRING)
        .equals(getVersion().toHttpHeaderValue());
  }
  return false;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Return the full url of the websocket location of the given {@link WebSocketHttpExchange}
 */
protected static String getWebSocketLocation(WebSocketHttpExchange exchange) {
  String scheme;
  if ("https".equals(exchange.getRequestScheme())) {
    scheme = "wss";
  } else {
    scheme = "ws";
  }
  return scheme + "://" + exchange.getRequestHeader(Headers.HOST_STRING) + exchange.getRequestURI();
}

代码示例来源:origin: wildfly/wildfly

/**
 * 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);
  }
}

代码示例来源:origin: wildfly/wildfly

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));
  }
}

代码示例来源:origin: syncany/syncany

String originHeader = exchange.getRequestHeader("Origin");

代码示例来源:origin: wildfly/wildfly

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;
  }
}

代码示例来源:origin: wildfly/wildfly

@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;
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
public boolean matches(final WebSocketHttpExchange exchange) {
  if (exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_KEY_STRING) != null &&
      exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_VERSION_STRING) != null) {
    return exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_VERSION_STRING)
        .equals(getVersion().toHttpHeaderValue());
  }
  return false;
}

代码示例来源:origin: io.undertow/undertow-core

@Override
public boolean matches(final WebSocketHttpExchange exchange) {
  if (exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_KEY_STRING) != null &&
      exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_VERSION_STRING) != null) {
    return exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_VERSION_STRING)
        .equals(getVersion().toHttpHeaderValue());
  }
  return false;
}

代码示例来源:origin: io.undertow/undertow-core

/**
 * Return the full url of the websocket location of the given {@link WebSocketHttpExchange}
 */
protected static String getWebSocketLocation(WebSocketHttpExchange exchange) {
  String scheme;
  if ("https".equals(exchange.getRequestScheme())) {
    scheme = "wss";
  } else {
    scheme = "ws";
  }
  return scheme + "://" + exchange.getRequestHeader(Headers.HOST_STRING) + exchange.getRequestURI();
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * Return the full url of the websocket location of the given {@link WebSocketHttpExchange}
 */
protected static String getWebSocketLocation(WebSocketHttpExchange exchange) {
  String scheme;
  if ("https".equals(exchange.getRequestScheme())) {
    scheme = "wss";
  } else {
    scheme = "ws";
  }
  return scheme + "://" + exchange.getRequestHeader(Headers.HOST_STRING) + exchange.getRequestURI();
}

代码示例来源:origin: io.undertow/undertow-core

/**
 * 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);
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * 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);
  }
}

代码示例来源:origin: io.undertow/undertow-core

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));
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

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));
  }
}

代码示例来源:origin: networknt/light

String originHeader = exchange.getRequestHeader("Origin");
boolean allowedOriginHeader = (originHeader == null ||
    LightServer.WEBSOCKET_ALLOWED_ORIGIN_HEADER.matcher(originHeader).matches());

代码示例来源:origin: io.undertow/undertow-core

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;
  }
}

代码示例来源:origin: io.undertow/undertow-core

@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;
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

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;
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@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;
  }
}

相关文章