mobile/android/base/sync/net/ResourceDelegate.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/sync/net/ResourceDelegate.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.sync.net;
     1.9 +
    1.10 +import java.io.IOException;
    1.11 +import java.security.GeneralSecurityException;
    1.12 +
    1.13 +import ch.boye.httpclientandroidlib.HttpResponse;
    1.14 +import ch.boye.httpclientandroidlib.client.ClientProtocolException;
    1.15 +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase;
    1.16 +import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient;
    1.17 +
    1.18 +/**
    1.19 + * ResourceDelegate implementers must ensure that HTTP responses
    1.20 + * are fully consumed to ensure that connections are returned to
    1.21 + * the pool:
    1.22 + *
    1.23 + *          EntityUtils.consume(entity);
    1.24 + * @author rnewman
    1.25 + *
    1.26 + */
    1.27 +public interface ResourceDelegate {
    1.28 +  // Request augmentation.
    1.29 +  AuthHeaderProvider getAuthHeaderProvider();
    1.30 +  void addHeaders(HttpRequestBase request, DefaultHttpClient client);
    1.31 +
    1.32 +  /**
    1.33 +   * The value of the User-Agent header to include with the request.
    1.34 +   *
    1.35 +   * @return User-Agent header value; null means do not set User-Agent header.
    1.36 +   */
    1.37 +  public String getUserAgent();
    1.38 +
    1.39 +  // Response handling.
    1.40 +
    1.41 +  /**
    1.42 +   * Override this to handle an HttpResponse.
    1.43 +   *
    1.44 +   * ResourceDelegate implementers <b>must</b> ensure that HTTP responses are
    1.45 +   * fully consumed to ensure that connections are returned to the pool, for
    1.46 +   * example by calling <code>EntityUtils.consume(response.getEntity())</code>.
    1.47 +   */
    1.48 +  void handleHttpResponse(HttpResponse response);
    1.49 +  void handleHttpProtocolException(ClientProtocolException e);
    1.50 +  void handleHttpIOException(IOException e);
    1.51 +
    1.52 +  // During preparation.
    1.53 +  void handleTransportException(GeneralSecurityException e);
    1.54 +
    1.55 +  // Connection parameters.
    1.56 +  int connectionTimeout();
    1.57 +  int socketTimeout();
    1.58 +}

mercurial