Bug 293046 XMLHttpRequest.overrideMimeType() makes loading abort for non-XML

patch by Wladimir Palant <trev@gtchat.de> r=jst sr=darin
This commit is contained in:
cbiesinger%web.de 2005-08-17 16:54:25 +00:00
Родитель bf0613c434
Коммит ee62d3bd19
1 изменённых файлов: 24 добавлений и 15 удалений

Просмотреть файл

@ -1136,7 +1136,16 @@ nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
if (NS_SUCCEEDED(rv)) {
NS_ASSERTION(copyStream, "NS_NewByteInputStream lied");
rv = xmlHttpRequest->mXMLParserStreamListener->OnDataAvailable(xmlHttpRequest->mReadRequest,xmlHttpRequest->mContext,copyStream,toOffset,count);
nsresult parsingResult = xmlHttpRequest->mXMLParserStreamListener
->OnDataAvailable(xmlHttpRequest->mReadRequest,
xmlHttpRequest->mContext,
copyStream, toOffset, count);
// No use to continue parsing if we failed here, but we
// should still finish reading the stream
if (NS_FAILED(parsingResult)) {
xmlHttpRequest->mState &= ~XML_HTTP_REQUEST_PARSEBODY;
}
}
}
@ -1223,12 +1232,18 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
}
if (mOverrideMimeType.IsEmpty()) {
// If we are not overriding the mime type, we can gain a huge
// performance win by not even trying to parse non-XML data. This
// also protects us from the situation where we have an XML
// document and sink, but HTML (or other) parser, which can
// produce unreliable results.
nsresult status;
request->GetStatus(&status);
if (NS_SUCCEEDED(status)) {
if (!mOverrideMimeType.IsEmpty()) {
channel->SetContentType(mOverrideMimeType);
}
// We can gain a huge performance win by not even trying to
// parse non-XML data. This also protects us from the situation
// where we have an XML document and sink, but HTML (or other)
// parser, which can produce unreliable results.
nsCAutoString type;
channel->GetContentType(type);
@ -1236,14 +1251,8 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
mState &= ~XML_HTTP_REQUEST_PARSEBODY;
}
} else {
nsresult status;
request->GetStatus(&status);
if (NS_SUCCEEDED(status)) {
channel->SetContentType(mOverrideMimeType);
} else {
// The request failed, so we shouldn't be parsing anyway
mState &= ~XML_HTTP_REQUEST_PARSEBODY;
}
// The request failed, so we shouldn't be parsing anyway
mState &= ~XML_HTTP_REQUEST_PARSEBODY;
}
if (mState & XML_HTTP_REQUEST_PARSEBODY) {