Add opt-in timeouts to provisioning websocket

This commit is contained in:
ravi-signal
2024-12-18 18:45:53 -06:00
committed by GitHub
parent 6460327372
commit 68f27be7cd
10 changed files with 310 additions and 37 deletions

View File

@@ -1,15 +0,0 @@
package org.whispersystems.websocket;
/**
* Class containing constants and shared logic for handling stories.
* <p>
* In particular, it defines the way we interpret the X-Signal-Receive-Stories header
* which is used by both WebSockets and by the REST API.
*/
public class Stories {
public final static String X_SIGNAL_RECEIVE_STORIES = "X-Signal-Receive-Stories";
public static boolean parseReceiveStoriesHeader(String s) {
return "true".equals(s);
}
}

View File

@@ -98,8 +98,12 @@ public class WebSocketClient {
}
public boolean shouldDeliverStories() {
String value = session.getUpgradeRequest().getHeader(Stories.X_SIGNAL_RECEIVE_STORIES);
return Stories.parseReceiveStoriesHeader(value);
String value = session.getUpgradeRequest().getHeader(WebsocketHeaders.X_SIGNAL_RECEIVE_STORIES);
return WebsocketHeaders.parseReceiveStoriesHeader(value);
}
public boolean supportsProvisioningSocketTimeouts() {
return session.getUpgradeRequest().getHeader(WebsocketHeaders.X_SIGNAL_WEBSOCKET_TIMEOUT_HEADER) != null;
}
private long generateRequestId() {

View File

@@ -0,0 +1,13 @@
package org.whispersystems.websocket;
/**
* Class containing constants and shared logic for headers used in websocket upgrade requests.
*/
public class WebsocketHeaders {
public final static String X_SIGNAL_RECEIVE_STORIES = "X-Signal-Receive-Stories";
public static final String X_SIGNAL_WEBSOCKET_TIMEOUT_HEADER = "X-Signal-Websocket-Timeout";
public static boolean parseReceiveStoriesHeader(String s) {
return "true".equals(s);
}
}