diff --git a/content/base/public/nsIXMLHttpRequest.idl b/content/base/public/nsIXMLHttpRequest.idl
index 92468271e1d..8ca14616964 100644
--- a/content/base/public/nsIXMLHttpRequest.idl
+++ b/content/base/public/nsIXMLHttpRequest.idl
@@ -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 send
method is invoked.
+ *
+ * @param mimetype The type used to override that returned by the server
+ * (if any).
+ */
+ void overrideMimeType(in string mimetype);
};
diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp
index 8ff1d072a16..90c829d0287 100644
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -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 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)
diff --git a/content/base/src/nsXMLHttpRequest.h b/content/base/src/nsXMLHttpRequest.h
index d9acd9f6d0c..57d11fe657f 100644
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -161,6 +161,7 @@ protected:
PRInt32 mStatus;
PRBool mAsync;
+ nsCString mOverrideMimeType;
};
#endif