NS_WARNING("server response was unexpected"); return NS_ERROR_UNEXPECTED;
if (code == 200) { if (mInterval) { mChannel = nsnull; if (++mNonPartialCount > MAX_RETRY_COUNT) { NS_WARNING("unable to fetch a byte range; giving up"); return NS_ERROR_FAILURE; }  StartTimer(mInterval * mNonPartialCount); return NS_ERROR_DOWNLOAD_NOT_PARTIAL; }    } else { NS_WARNING("server response was unexpected"); return NS_ERROR_UNEXPECTED; } } else {   mNonPartialCount = 0;
nsIncrementalDownload::OnStartRequest(nsIRequest *request,                                      nsISupports *context){  nsresult rv;  nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(request, &rv);  if (NS_FAILED(rv))    return rv;  // Ensure that we are receiving a 206 response.  PRUint32 code;  rv = http->GetResponseStatus(&code);  if (NS_FAILED(rv))    return rv;  if (code != 206) {    // We may already have the entire file downloaded, in which case    // our request for a range beyond the end of the file would have    // been met with an error response code.    if (code == 416 && mTotalSize == nsInt64(-1)) {      mTotalSize = mCurrentSize;      // Return an error code here to suppress OnDataAvailable.      return NS_ERROR_DOWNLOAD_COMPLETE;    }    NS_WARNING("server response was unexpected");    return NS_ERROR_UNEXPECTED;  }  // Do special processing after the first response.  if (mTotalSize == nsInt64(-1)) {    // Update knowledge of mFinalURI    rv = http->GetURI(getter_AddRefs(mFinalURI));    if (NS_FAILED(rv))      return rv;    // OK, read the Content-Range header to determine the total size of this    // download file.    nsCAutoString buf;    rv = http->GetResponseHeader(NS_LITERAL_CSTRING("Content-Range"), buf);    if (NS_FAILED(rv))      return rv;    PRInt32 slash = buf.FindChar('/');    if (slash == kNotFound) {      NS_WARNING("server returned invalid Content-Range header!");      return NS_ERROR_UNEXPECTED;    }    if (PR_sscanf(buf.get() + slash + 1, "%lld", (PRInt64 *) &mTotalSize) != 1)      return NS_ERROR_UNEXPECTED;    // Notify observer that we are starting...    rv = CallOnStartRequest();    if (NS_FAILED(rv))      return rv;  }  // Adjust mChunkSize accordingly if mCurrentSize is close to mTotalSize.  nsInt64 diff = mTotalSize - mCurrentSize;  if (diff < nsInt64(mChunkSize))    mChunkSize = PRUint32(diff);  mChunk = new char[mChunkSize];  if (!mChunk)    rv = NS_ERROR_OUT_OF_MEMORY;  return rv;}