Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/tests/xhr.js | 14 +++++++++++- dlls/mshtml/xmlhttprequest.c | 43 ++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/dlls/mshtml/tests/xhr.js b/dlls/mshtml/tests/xhr.js index 303c4ad..3ae86e6 100644 --- a/dlls/mshtml/tests/xhr.js +++ b/dlls/mshtml/tests/xhr.js @@ -71,7 +71,7 @@ function test_xhr() { }
function test_content_types() { - var xhr = new XMLHttpRequest(), types, i = 0; + var xhr = new XMLHttpRequest(), types, i = 0, override = false; var v = document.documentMode;
var types = [ @@ -97,6 +97,18 @@ function test_content_types() { else ok(xhr.responseXML === null, "unexpected non-null responseXML for " + types[i]);
+ if(("overrideMimeType" in xhr) && !override) { + override = true; + xhr = new XMLHttpRequest(); + xhr.onload = onload; + xhr.open("POST", "echo.php", true); + xhr.setRequestHeader("X-Test", "True"); + xhr.overrideMimeType(types[i]); + xhr.send(xml); + return; + } + override = false; + if(++i >= types.length) { if(types === xml_types) { next_test(); diff --git a/dlls/mshtml/xmlhttprequest.c b/dlls/mshtml/xmlhttprequest.c index 0fadc10..ee1549a 100644 --- a/dlls/mshtml/xmlhttprequest.c +++ b/dlls/mshtml/xmlhttprequest.c @@ -121,6 +121,7 @@ struct HTMLXMLHttpRequest { LONG ref; nsIXMLHttpRequest *nsxhr; XMLHttpReqEventListener *event_listener; + char *type_override; };
static void detach_xhr_event_listener(XMLHttpReqEventListener *event_listener) @@ -283,6 +284,7 @@ static ULONG WINAPI HTMLXMLHttpRequest_Release(IHTMLXMLHttpRequest *iface) release_event_target(&This->event_target); release_dispex(&This->event_target.dispex); nsIXMLHttpRequest_Release(This->nsxhr); + heap_free(This->type_override); heap_free(This); }
@@ -380,16 +382,20 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_responseXML(IHTMLXMLHttpRequest *if const char *type; nsresult nsres;
- nsACString_InitDepend(&header, "Content-Type"); nsACString_InitDepend(&nscstr, NULL); - nsres = nsIXMLHttpRequest_GetResponseHeader(This->nsxhr, &header, &nscstr); - nsACString_Finish(&header); - if(NS_FAILED(nsres)) - type = NULL; + if(This->type_override) + type = This->type_override; else { - nsACString_GetData(&nscstr, &type); - if(!type[0]) + nsACString_InitDepend(&header, "Content-Type"); + nsres = nsIXMLHttpRequest_GetResponseHeader(This->nsxhr, &header, &nscstr); + nsACString_Finish(&header); + if(NS_FAILED(nsres)) type = NULL; + else { + nsACString_GetData(&nscstr, &type); + if(!type[0]) + type = NULL; + } } if(type && stricmp(type, "text/xml") && stricmp(type, "application/xml")) { size_t len = strlen(type); @@ -993,10 +999,29 @@ static HRESULT WINAPI HTMLXMLHttpRequest_private_get_withCredentials(IWineXMLHtt static HRESULT WINAPI HTMLXMLHttpRequest_private_overrideMimeType(IWineXMLHttpRequestPrivate *iface, BSTR mimeType) { HTMLXMLHttpRequest *This = impl_from_IWineXMLHttpRequestPrivate(iface); + WCHAR *lowercase = NULL; + char *type = NULL; + nsAString nsstr;
- FIXME("(%p)->(%s)\n", This, debugstr_w(mimeType)); + TRACE("(%p)->(%s)\n", This, debugstr_w(mimeType));
- return E_NOTIMPL; + if(mimeType) { + if(!(lowercase = heap_strdupW(mimeType))) + return E_OUTOFMEMORY; + _wcslwr(lowercase); + if(!(type = heap_strdupWtoA(lowercase))) { + heap_free(lowercase); + return E_OUTOFMEMORY; + } + } + heap_free(This->type_override); + This->type_override = type; + + nsAString_InitDepend(&nsstr, lowercase); + nsIXMLHttpRequest_SlowOverrideMimeType(This->nsxhr, &nsstr); + nsAString_Finish(&nsstr); + heap_free(lowercase); + return S_OK; }
static HRESULT WINAPI HTMLXMLHttpRequest_private_put_onerror(IWineXMLHttpRequestPrivate *iface, VARIANT v)