Skip to content

Commit

Permalink
Merge pull request #1693 from DinithHerath/master
Browse files Browse the repository at this point in the history
Add implementation to preserve websocket headers with null check for preserved header value
  • Loading branch information
DinithHerath committed Dec 6, 2023
2 parents 5b7439a + e96d025 commit 348803f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class WebsocketConstants {

public static final String WEBSOCKET_CUSTOM_HEADER_PREFIX = "websocket.custom.header.";
public static final String WEBSOCKET_CUSTOM_HEADER_CONFIG = "ws.custom.header";
public static final String WEBSOCKET_HEADERS_PRESERVE_CONFIG = "ws.headers.preserve";
public static final String WEBSOCKET_HOSTNAME_VERIFICATION_CONFIG = "ws.client.enable.hostname.verification";

public static final String WEBSOCKET_SUBPROTOCOL = "websocket.subprotocol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ public void sendMessage(MessageContext msgCtx, String targetEPR, OutTransportInf
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}

/*
* Preserve the specified headers from the original request by adding to the customHeaders map.
* Headers present in this map won't be set at Netty level.
*/
Parameter preserveWebSocketHeadersParameter = msgCtx.getTransportOut()
.getParameter(WebsocketConstants.WEBSOCKET_HEADERS_PRESERVE_CONFIG);
if (preserveWebSocketHeadersParameter != null && preserveWebSocketHeadersParameter.getValue() != null &&
!preserveWebSocketHeadersParameter.getValue().toString().isEmpty()) {
String preservableHeaders = preserveWebSocketHeadersParameter.getValue().toString();
for (String header : preservableHeaders.split(",")) {
Object headerValue = msgCtx.getProperty(header);
if (headerValue != null) {
customHeaders.put(header, headerValue);
}
}
}

/*
* Get all the message property names and check whether the properties with the websocket custom header
* prefix are exist in the property map.
Expand Down

0 comments on commit 348803f

Please sign in to comment.