Fix for bug 122305. XMLHttpRequest now has a way to override the mime type of the incoming stream. r=heikki, sr=jst

This commit is contained in:
vidur%netscape.com 2002-02-05 02:10:52 +00:00
Родитель 580e33204e
Коммит 24f25e6829
7 изменённых файлов: 65 добавлений и 0 удалений

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

@ -586,6 +586,12 @@ nsSchemaLoader::Load(const nsAReadableString& schemaURI,
return rv;
}
// Force the mimetype of the returned stream to be xml.
rv = request->OverrideMimeType("text/xml");
if (NS_FAILED(rv)) {
return rv;
}
rv = request->Send(nsnull);
if (NS_FAILED(rv)) {
return rv;
@ -636,6 +642,12 @@ nsSchemaLoader::LoadAsync(const nsAReadableString& schemaURI,
return rv;
}
// Force the mimetype of the returned stream to be xml.
rv = request->OverrideMimeType("text/xml");
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIDOMEventListener> listener;
LoadListener* listenerInst = new LoadListener(this, aListener, request);
if (!listenerInst) {

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

@ -326,6 +326,12 @@ nsWSDLLoadRequest::LoadDefinition(const nsAReadableString& aURI)
return rv;
}
// Force the mimetype of the returned stream to be xml.
rv = mRequest->OverrideMimeType("text/xml");
if (NS_FAILED(rv)) {
return rv;
}
if (!mIsSync) {
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mRequest));
if (!target) {

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

@ -224,6 +224,17 @@ interface nsIXMLHttpRequest : nsISupports {
* 4 COMPLETED Finished with all operations.
*/
readonly attribute long readyState;
/**
* Override the mime type returned by the server (if any). This may
* be used, for example, to force a stream to be treated and parsed
* as text/xml, even if the server does not report it as such. This
* must be done before the <code>send</code> method is invoked.
*
* @param mimetype The type used to override that returned by the server
* (if any).
*/
void overrideMimeType(in string mimetype);
};

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

@ -814,6 +814,14 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
mReadRequest = request;
mContext = ctxt;
ChangeState(XML_HTTP_REQUEST_LOADED);
if (!mOverrideMimeType.IsEmpty()) {
nsresult status;
request->GetStatus(&status);
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel && NS_SUCCEEDED(status)) {
channel->SetContentType(mOverrideMimeType.get());
}
}
return mXMLParserStreamListener->OnStartRequest(request,ctxt);
}
@ -1214,6 +1222,15 @@ nsXMLHttpRequest::GetReadyState(PRInt32 *aState)
return NS_OK;
}
/* void overrideMimeType(in string mimetype); */
NS_IMETHODIMP
nsXMLHttpRequest::OverrideMimeType(const char* aMimeType)
{
// XXX Should we do some validation here?
mOverrideMimeType.Assign(aMimeType);
return NS_OK;
}
// nsIDOMEventListener
nsresult
nsXMLHttpRequest::HandleEvent(nsIDOMEvent* aEvent)

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

@ -161,6 +161,7 @@ protected:
PRInt32 mStatus;
PRBool mAsync;
nsCString mOverrideMimeType;
};
#endif

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

@ -586,6 +586,12 @@ nsSchemaLoader::Load(const nsAReadableString& schemaURI,
return rv;
}
// Force the mimetype of the returned stream to be xml.
rv = request->OverrideMimeType("text/xml");
if (NS_FAILED(rv)) {
return rv;
}
rv = request->Send(nsnull);
if (NS_FAILED(rv)) {
return rv;
@ -636,6 +642,12 @@ nsSchemaLoader::LoadAsync(const nsAReadableString& schemaURI,
return rv;
}
// Force the mimetype of the returned stream to be xml.
rv = request->OverrideMimeType("text/xml");
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIDOMEventListener> listener;
LoadListener* listenerInst = new LoadListener(this, aListener, request);
if (!listenerInst) {

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

@ -326,6 +326,12 @@ nsWSDLLoadRequest::LoadDefinition(const nsAReadableString& aURI)
return rv;
}
// Force the mimetype of the returned stream to be xml.
rv = mRequest->OverrideMimeType("text/xml");
if (NS_FAILED(rv)) {
return rv;
}
if (!mIsSync) {
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mRequest));
if (!target) {