From ee62d3bd199bc49bf9025e6836225330e1fdfdc8 Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Wed, 17 Aug 2005 16:54:25 +0000 Subject: [PATCH] Bug 293046 XMLHttpRequest.overrideMimeType() makes loading abort for non-XML patch by Wladimir Palant r=jst sr=darin --- .../xmlextras/base/src/nsXMLHttpRequest.cpp | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp b/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp index 094d468b284d..03f9d469b50b 100644 --- a/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp +++ b/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp @@ -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) {