diff --git a/netwerk/protocol/file/nsFileChannel.cpp b/netwerk/protocol/file/nsFileChannel.cpp index ba30ed9a6394..133a60ae0f48 100644 --- a/netwerk/protocol/file/nsFileChannel.cpp +++ b/netwerk/protocol/file/nsFileChannel.cpp @@ -312,10 +312,14 @@ nsFileChannel::MakeFileInputStream(nsIFile *file, bool isDir; nsresult rv = file->IsDirectory(&isDir); if (NS_FAILED(rv)) { - // canonicalize error message - if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) - rv = NS_ERROR_FILE_NOT_FOUND; - return rv; + if (NS_ERROR_FILE_NOT_FOUND == rv || + NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv) { + // We don't return "Not Found" errors here. Since we could not find + // the file, it's not a directory anyway. + isDir = false; + } else { + return rv; + } } if (isDir) { @@ -323,7 +327,8 @@ nsFileChannel::MakeFileInputStream(nsIFile *file, if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) contentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT); } else { - rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file); + rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file, -1, -1, + nsIFileInputStream::DEFER_OPEN); if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) { // Use file extension to infer content type nsCOMPtr mime = do_GetService("@mozilla.org/mime;1", &rv); @@ -407,8 +412,14 @@ nsFileChannel::OpenContentStream(bool async, nsIInputStream **result, if (ContentLength64() < 0) { PRInt64 size; rv = file->GetFileSize(&size); - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) { + if (NS_ERROR_FILE_NOT_FOUND == rv || + NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv) { + size = 0; + } else { + return rv; + } + } SetContentLength64(size); } if (!contentType.IsEmpty())