Skip to content

HTTP Transport

Jonathan Edey edited this page Oct 9, 2024 · 1 revision

New Default Transport: ApacheHttp2Transport

Starting in v9.4.0, the default HttpTransport used in the SDK has changed from Google APIs default HTTP Transport (NetHttpTransport) to an Admin SDK implementation of HttpTransport with HTTP/2 support (ApacheHttp2Transport). This is in an effort to provide HTTP/2 support needed for increased FCM requests with the deprecation of the FCM batch endpoint.

This change requires no action from developers and custom HTTP Transports passed to FirebaseAppOptions will continue to override this new default transport.

Additionally, for more control, the ApacheHttp2Transport can be further configured by passing in a custom CloseableHttpAsyncClient as a parameter to ApacheHttp2Transport() as follows:

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.internal.ApacheHttp2Transport;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;

// Setup any custom CloseableHttpAsyncClient
CloseableHttpAsyncClient client = HttpAsyncClients.createHttp2System();

// Set transport in app options
FirebaseOptions options = FirebaseOptions.builder()
    .setHttpTransport(new ApacheHttp2Transport(client))
    .build();

FirebaseApp app = FirebaseApp.initializeApp(options);

Using Google APIs Transports

Developers who wish to continue to use the Google APIs default transport, can do so using the following setup:

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.api.client.googleapis.util.Utils

// Set transport in app options
FirebaseOptions options = FirebaseOptions.builder()
    .setHttpTransport(Utils.getDefaultTransport())
    .build();

FirebaseApp app = FirebaseApp.initializeApp(options);
Clone this wiki locally