Add routing for stories.

This commit is contained in:
erik-signal
2022-10-05 10:32:10 -04:00
committed by Erik Osheim
parent c2ab72c77e
commit 966c3a8f47
20 changed files with 425 additions and 86 deletions

View File

@@ -0,0 +1,15 @@
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

@@ -35,13 +35,12 @@ public class WebSocketClient {
public WebSocketClient(Session session, RemoteEndpoint remoteEndpoint,
WebSocketMessageFactory messageFactory,
Map<Long, CompletableFuture<WebSocketResponseMessage>> pendingRequestMapper)
{
this.session = session;
this.remoteEndpoint = remoteEndpoint;
this.messageFactory = messageFactory;
Map<Long, CompletableFuture<WebSocketResponseMessage>> pendingRequestMapper) {
this.session = session;
this.remoteEndpoint = remoteEndpoint;
this.messageFactory = messageFactory;
this.pendingRequestMapper = pendingRequestMapper;
this.created = System.currentTimeMillis();
this.created = System.currentTimeMillis();
}
public CompletableFuture<WebSocketResponseMessage> sendRequest(String verb, String path,
@@ -92,6 +91,11 @@ public class WebSocketClient {
session.close(code, message);
}
public boolean shouldDeliverStories() {
String value = session.getUpgradeRequest().getHeader(Stories.X_SIGNAL_RECEIVE_STORIES);
return Stories.parseReceiveStoriesHeader(value);
}
public void hardDisconnectQuietly() {
try {
session.disconnect();