Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c7686b9 authored by Grace Kloba's avatar Grace Kloba Committed by Android Git Automerger
Browse files

am dbfd5e25: am 627728d2: am a6ece18d: Merge "Added the subset of partial...

am dbfd5e25: am 627728d2: am a6ece18d: Merge "Added the subset of partial content support so that we can continue the interrupted request to support streaming the content even with a brief disconnection." into froyo
parents aba598cc dbfd5e25
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.ParseException;
import org.apache.http.ProtocolVersion;

@@ -72,6 +73,10 @@ class Request {

    int mFailCount = 0;

    // This will be used to set the Range field if we retry a connection. This
    // is http/1.1 feature.
    private int mReceivedBytes = 0;

    private InputStream mBodyProvider;
    private int mBodyLength;

@@ -241,7 +246,6 @@ class Request {

        StatusLine statusLine = null;
        boolean hasBody = false;
        boolean reuse = false;
        httpClientConnection.flush();
        int statusCode = 0;

@@ -264,6 +268,8 @@ class Request {
        if (hasBody)
            entity = httpClientConnection.receiveResponseEntity(header);

        boolean supportPartialContent = v.greaterEquals(HttpVersion.HTTP_1_1);

        if (entity != null) {
            InputStream is = entity.getContent();

@@ -306,6 +312,7 @@ class Request {

                    if (len != -1) {
                        count += len;
                        if (supportPartialContent) mReceivedBytes += len;
                    }
                    if (len == -1 || count >= lowWater) {
                        if (HttpLog.LOGV) HttpLog.v("Request.readResponse() " + count);
@@ -324,7 +331,13 @@ class Request {
                if (HttpLog.LOGV) HttpLog.v( "readResponse() handling " + e);
            } catch(IOException e) {
                // don't throw if we have a non-OK status code
                if (statusCode == HttpStatus.SC_OK) {
                if (statusCode == HttpStatus.SC_OK
                        || statusCode == HttpStatus.SC_PARTIAL_CONTENT) {
                    if (supportPartialContent && count > 0) {
                        // if there is uncommited content, we should commit them
                        // as we will continue the request
                        mEventHandler.data(buf, count);
                    }
                    throw e;
                }
            } finally {
@@ -411,6 +424,15 @@ class Request {
            }
            setBodyProvider(mBodyProvider, mBodyLength);
        }

        if (mReceivedBytes > 0) {
            // reset the fail count as we continue the request
            mFailCount = 0;
            // set the "Range" header to indicate that the retry will continue
            // instead of restarting the request
            HttpLog.v("*** Request.reset() to range:" + mReceivedBytes);
            mHttpRequest.setHeader("Range", "bytes=" + mReceivedBytes + "-");
        }
    }

    /**
+12 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ class LoadListener extends Handler implements EventHandler {

    // Standard HTTP status codes in a more representative format
    private static final int HTTP_OK = 200;
    private static final int HTTP_PARTIAL_CONTENT = 206;
    private static final int HTTP_MOVED_PERMANENTLY = 301;
    private static final int HTTP_FOUND = 302;
    private static final int HTTP_SEE_OTHER = 303;
@@ -328,6 +329,17 @@ class LoadListener extends Handler implements EventHandler {
    // Does the header parsing work on the WebCore thread.
    private void handleHeaders(Headers headers) {
        if (mCancelled) return;

        // Note: the headers we care in LoadListeners, like
        // content-type/content-length, should not be updated for partial
        // content. Just skip here and go ahead with adding data.
        if (mStatusCode == HTTP_PARTIAL_CONTENT) {
            // we don't support cache for partial content yet
            WebViewWorker.getHandler().obtainMessage(
                    WebViewWorker.MSG_REMOVE_CACHE, this).sendToTarget();
            return;
        }

        mHeaders = headers;

        long contentLength = headers.getContentLength();