henriqueolliveira / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

HttpRequest connectTimeout and readTimeout #156

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
External references, such as a standards document, or specification?

http://download.oracle.com/javase/6/docs/api/java/net/URLConnection.html#setConn
ectTimeout(int)
http://download.oracle.com/javase/6/docs/api/java/net/URLConnection.html#setRead
Timeout(int)

Java environments (e.g. Java 6, Android 2.3, App Engine 1.4.2, or All)?

All

Please describe the feature requested.

We will add these two fields to HttpRequest:

public final class HttpRequest {
  /** Timeout in milliseconds to establish a connection or {@code 0} for an infinite timeout. */
  public int connectTimeout = 20 * 1000;

  /** Timeout in milliseconds to read data from an established connection or {@code 0} for an infinite timeout. */
  public int readTimeout = 20 * 1000;
}

This is much like the java.net.URLConnection and Apache HTTP Client allow you 
to do.  On App engine's UrlFetchService, we can simply set the Deadline to the 
sum of the two timeouts.  By building this feature on top of HttpRequest, we 
allow the code to be portable across the various HTTP libraries.

Note that we will not add similar fields to HttpTransport.  Instead, users will 
need to use HttpRequestFactory (see Issue 155), e.g.:

  public static HttpRequestFactory setTimeouts(HttpTransport transport) {
    return transport.createRequestFactory(new HttpRequestHandler() {
      public void handle(HttpRequest request) {
        request.readTimeout = request.connectTimeout = 10000;
      }
    });
  }

Original issue reported on code.google.com by yan...@google.com on 20 Mar 2011 at 3:09

GoogleCodeExporter commented 9 years ago
http://codereview.appspot.com/4358050/

Original comment by yan...@google.com on 5 Apr 2011 at 1:11

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 5 Apr 2011 at 6:42