use of org.whispersystems.signalservice.api.messages.calls.CallingResponse in project Signal-Android by WhisperSystems.
the class PushServiceSocket method makeCallingRequest.
public CallingResponse makeCallingRequest(long requestId, String url, String httpMethod, List<Pair<String, String>> headers, byte[] body) {
ConnectionHolder connectionHolder = getRandom(serviceClients, random);
OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().followRedirects(false).connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
RequestBody requestBody = body != null ? RequestBody.create(null, body) : null;
Request.Builder builder = new Request.Builder().url(url).method(httpMethod, requestBody);
if (headers != null) {
for (Pair<String, String> header : headers) {
builder.addHeader(header.first(), header.second());
}
}
Request request = builder.build();
for (int i = 0; i < MAX_FOLLOW_UPS; i++) {
try (Response response = okHttpClient.newCall(request).execute()) {
int responseStatus = response.code();
if (responseStatus != 307) {
return new CallingResponse.Success(requestId, responseStatus, response.body() != null ? response.body().bytes() : new byte[0]);
}
String location = response.header("Location");
HttpUrl newUrl = location != null ? request.url().resolve(location) : null;
if (newUrl != null) {
request = request.newBuilder().url(newUrl).build();
} else {
return new CallingResponse.Error(requestId, new IOException("Received redirect without a valid Location header"));
}
} catch (IOException e) {
Log.w(TAG, "Exception during ringrtc http call.", e);
return new CallingResponse.Error(requestId, e);
}
}
Log.w(TAG, "Calling request max redirects exceeded");
return new CallingResponse.Error(requestId, new IOException("Redirect limit exceeded"));
}
use of org.whispersystems.signalservice.api.messages.calls.CallingResponse in project Signal-Android by WhisperSystems.
the class SignalCallManager method onSendHttpRequest.
@Override
public void onSendHttpRequest(long requestId, @NonNull String url, @NonNull CallManager.HttpMethod httpMethod, @Nullable List<HttpHeader> headers, @Nullable byte[] body) {
if (callManager == null) {
Log.w(TAG, "Unable to send http request, call manager is not initialized");
return;
}
Log.i(TAG, "onSendHttpRequest(): request_id: " + requestId);
networkExecutor.execute(() -> {
List<Pair<String, String>> headerPairs;
if (headers != null) {
headerPairs = Stream.of(headers).map(header -> new Pair<>(header.getName(), header.getValue())).toList();
} else {
headerPairs = Collections.emptyList();
}
CallingResponse response = messageSender.makeCallingRequest(requestId, url, httpMethod.name(), headerPairs, body);
try {
if (response instanceof CallingResponse.Success) {
CallingResponse.Success success = (CallingResponse.Success) response;
callManager.receivedHttpResponse(requestId, success.getResponseStatus(), success.getResponseBody());
} else {
callManager.httpRequestFailed(requestId);
}
} catch (CallException e) {
Log.i(TAG, "Failed to process HTTP response/failure", e);
}
});
}
Aggregations