コード例 #1
1
  @Test
  public void echoXhrWithHeaders() throws Exception {
    AbstractXhrTransport xhrTransport = createXhrTransport();
    xhrTransport.setXhrStreamingDisabled(true);

    WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
    headers.add("auth", "123");
    testEcho(10, xhrTransport, headers);

    for (Map.Entry<String, HttpHeaders> entry : this.testFilter.requests.entrySet()) {
      HttpHeaders httpHeaders = entry.getValue();
      assertEquals("No auth header for: " + entry.getKey(), "123", httpHeaders.getFirst("auth"));
    }
  }
コード例 #2
0
  @Override
  public final ListenableFuture<WebSocketSession> doHandshake(
      WebSocketHandler webSocketHandler, WebSocketHttpHeaders headers, URI uri) {

    Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
    assertUri(uri);

    if (logger.isDebugEnabled()) {
      logger.debug("Connecting to " + uri);
    }

    HttpHeaders headersToUse = new HttpHeaders();
    if (headers != null) {
      for (String header : headers.keySet()) {
        if (!specialHeaders.contains(header.toLowerCase())) {
          headersToUse.put(header, headers.get(header));
        }
      }
    }

    List<String> subProtocols =
        ((headers != null) && (headers.getSecWebSocketProtocol() != null))
            ? headers.getSecWebSocketProtocol()
            : Collections.<String>emptyList();

    List<WebSocketExtension> extensions =
        ((headers != null) && (headers.getSecWebSocketExtensions() != null))
            ? headers.getSecWebSocketExtensions()
            : Collections.<WebSocketExtension>emptyList();

    return doHandshakeInternal(
        webSocketHandler,
        headersToUse,
        uri,
        subProtocols,
        extensions,
        Collections.<String, Object>emptyMap());
  }