のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

Ignoring Content-Length since Transfer-Encoding is also defined

    657     /**
    658      * Prepare target file based on given network response. Derives filename and
    659      * target size as needed.
    660      */
    661     private void processResponseHeaders(State state, HttpURLConnection conn)
    662             throws StopRequestException {
    663         // TODO: fallocate the entire file if header gave us specific length
    664 
    665         readResponseHeaders(state, conn); <====ここ
    666 
    667         state.mFilename = Helpers.generateSaveFile(
    668                 mContext,
    669                 mInfo.mUri,
    670                 mInfo.mHint,
    671                 state.mContentDisposition,
    672                 state.mContentLocation,
    673                 state.mMimeType,
    674                 mInfo.mDestination,
    675                 state.mContentLength,
    676                 mStorageManager);
    677 
    678         updateDatabaseFromHeaders(state);
    679         // check connectivity again now that we know the total size
    680         checkConnectivity();
    681     }
    703     private void readResponseHeaders(State state, HttpURLConnection conn)
    704             throws StopRequestException {
    705         state.mContentDisposition = conn.getHeaderField("Content-Disposition");
    706         state.mContentLocation = conn.getHeaderField("Content-Location");
    707 
    708         if (state.mMimeType == null) {
    709             state.mMimeType = Intent.normalizeMimeType(conn.getContentType());
    710         }
    711 
    712         state.mHeaderETag = conn.getHeaderField("ETag");
    713 
    714         final String transferEncoding = conn.getHeaderField("Transfer-Encoding");
    715         if (transferEncoding == null) {
    716             state.mContentLength = getHeaderFieldLong(conn, "Content-Length", -1);
    717         } else {
    718             Log.i(TAG, "Ignoring Content-Length since Transfer-Encoding is also defined"); <==ここ
    719             state.mContentLength = -1;
    720         }
    721 
    722         state.mTotalBytes = state.mContentLength;
    723         mInfo.mTotalBytes = state.mContentLength;
    724 
    725         final boolean noSizeInfo = state.mContentLength == -1
    726                 && (transferEncoding == null || !transferEncoding.equalsIgnoreCase("chunked"));
    727         if (!mInfo.mNoIntegrity && noSizeInfo) {
    728             throw new StopRequestException(STATUS_CANNOT_RESUME,
    729                     "can't know size of download, giving up");
    730         }
    731     }