657
658 * Prepare target file based on given network response.
661 private void processResponseHeaders(State state, HttpURLConnection conn)
662 throws StopRequestException {
663 TODO
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
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 }