For example, this might be used to disable request timeouts:
public class DisableTimeout implements HttpRequestInitializer {
public void initialize(HttpRequest request) {
request.setConnectTimeout(0);
request.setReadTimeout(0);
}
}
Sample usage with a request factory:
public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
return transport.createRequestFactory(new DisableTimeout());
}
More complex usage example:
public static HttpRequestFactory createRequestFactory2(HttpTransport transport) {
final DisableTimeout disableTimeout = new DisableTimeout();
return transport.createRequestFactory(new HttpRequestInitializer() {
public void initialize(HttpRequest request) {
disableTimeout.initialize(request);
}
});
}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Interface HttpRequestInitializer (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequestInitializer)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.HttpRequestInitializer)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.HttpRequestInitializer)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.HttpRequestInitializer)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.HttpRequestInitializer)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.HttpRequestInitializer)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.HttpRequestInitializer)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.HttpRequestInitializer) \n\n public interface HttpRequestInitializer\n\nHTTP request initializer.\n\nFor example, this might be used to disable request timeouts:\n\npublic class DisableTimeout implements HttpRequestInitializer {\npublic void initialize(HttpRequest request) {\nrequest.setConnectTimeout(0);\nrequest.setReadTimeout(0);\n}\n}\n\nSample usage with a request factory:\n\npublic static HttpRequestFactory createRequestFactory(HttpTransport transport) {\nreturn transport.createRequestFactory(new DisableTimeout());\n}\n\nMore complex usage example:\n\npublic static HttpRequestFactory createRequestFactory2(HttpTransport transport) {\nfinal DisableTimeout disableTimeout = new DisableTimeout();\nreturn transport.createRequestFactory(new HttpRequestInitializer() {\npublic void initialize(HttpRequest request) {\ndisableTimeout.initialize(request);\n}\n});\n}\n\nImplementations should normally be thread-safe.\n\nMethods\n-------\n\n### initialize(HttpRequest request)\n\n public abstract void initialize(HttpRequest request)\n\nInitializes a request."]]