Skip to content

Commit

Permalink
The Helidon WS client must include a 'Connection' header with a value…
Browse files Browse the repository at this point in the history
… of 'Upgrade' as part of the initial request.
  • Loading branch information
spericas committed Jan 5, 2024
1 parent 6f8367e commit d30db77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,6 +74,7 @@ class WsClientImpl implements WsClient {

ClientRequestHeaders headers = http1Client.prototype().defaultRequestHeaders();
headers.set(HEADER_UPGRADE_WS);
headers.set(HEADER_CONN_UPGRADE);
headers.set(HEADER_WS_VERSION);
headers.set(HeaderValues.CONTENT_LENGTH_ZERO);
if (clientConfig.protocolConfig().subProtocols().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

import io.helidon.http.HeaderNames;
import io.helidon.http.Headers;
import io.helidon.http.HttpPrologue;
import io.helidon.http.WritableHeaders;
Expand Down Expand Up @@ -54,6 +55,10 @@ public void onClose(WsSession session, int status, String reason) {
@Override
public Optional<Headers> onHttpUpgrade(HttpPrologue prologue, Headers headers) throws WsUpgradeException {
WritableHeaders<?> upgradeHeaders = WritableHeaders.create();

if (!headers.get(HeaderNames.CONNECTION).get().equals("Upgrade")) {
throw new WsUpgradeException("Must include 'Connection' header with value 'Upgrade'");
}
if (headers.contains(WsUpgrader.PROTOCOL)) {
List<String> subProtocols = headers.get(WsUpgrader.PROTOCOL).allValues(true);
if (subProtocols.contains("chat")) {
Expand Down

0 comments on commit d30db77

Please sign in to comment.