org.whispersystems.signalservice.internal.websocket.WebsocketResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
package org.whispersystems.signalservice.internal.websocket;
import org.whispersystems.signalservice.api.util.Preconditions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WebsocketResponse {
private final int status;
private final String body;
private final Map headers;
private final boolean unidentified;
WebsocketResponse(int status, String body, List headers, boolean unidentified) {
this(status, body, parseHeaders(headers), unidentified);
}
WebsocketResponse(int status, String body, Map headerMap, boolean unidentified) {
this.status = status;
this.body = body;
this.headers = headerMap;
this.unidentified = unidentified;
}
public int getStatus() {
return status;
}
public String getBody() {
return body;
}
public String getHeader(String key) {
return headers.get(Preconditions.checkNotNull(key.toLowerCase()));
}
public boolean isUnidentified() {
return unidentified;
}
private static Map parseHeaders(List rawHeaders) {
Map headers = new HashMap<>(rawHeaders.size());
for (String raw : rawHeaders) {
if (raw != null && !raw.isEmpty()) {
int colonIndex = raw.indexOf(":");
if (colonIndex > 0 && colonIndex < raw.length() - 1) {
String key = raw.substring(0, colonIndex).trim().toLowerCase();
String value = raw.substring(colonIndex + 1).trim();
headers.put(key, value);
}
}
}
return headers;
}
}