From: <mgu...@us...> - 2013-02-06 16:32:33
|
Revision: 8102 http://sourceforge.net/p/htmlunit/code/8102 Author: mguillem Date: 2013-02-06 16:32:30 +0000 (Wed, 06 Feb 2013) Log Message: ----------- Content-Type: text/plain;charset=utf-8 is an allowed header Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-02-06 16:27:22 UTC (rev 8101) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-02-06 16:32:30 UTC (rev 8102) @@ -728,14 +728,19 @@ */ private boolean isPreflightHeader(final String name, final String value) { if ("content-type".equals(name)) { - return !"application/x-www-form-urlencoded".equals(value) - && !"multipart/form-data".equals(value) && !"text/plain".equals(value); - } - if (!"accept".equals(name) && !"accept-language".equals(name) && !"content-language".equals(name) - && !"referer".equals(name) && !"accept-encoding".equals(name) && !"origin".equals(name)) { + if ("application/x-www-form-urlencoded".equals(value) + || "multipart/form-data".equals(value) + || "text/plain".equals(value) + || value.startsWith("text/plain;charset=")) { + return false; + } return true; } - return false; + if ("accept".equals(name) || "accept-language".equals(name) || "content-language".equals(name) + || "referer".equals(name) || "accept-encoding".equals(name) || "origin".equals(name)) { + return false; + } + return true; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java 2013-02-06 16:27:22 UTC (rev 8101) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java 2013-02-06 16:32:30 UTC (rev 8102) @@ -176,10 +176,20 @@ @Alerts(IE = { "4", "200", "null", "null", "null", "null" }, DEFAULT = { "4", "200", "§§URL§§", "§§URL§§", "GET", "x-pingother" }) public void preflight() throws Exception { - doPreflightTestAllowedMethods("POST, GET, OPTIONS"); + doPreflightTestAllowedMethods("POST, GET, OPTIONS", "text/plain"); } /** + * @throws Exception if the test fails. + */ + @Test + @Alerts(IE = { "4", "200", "null", "null", "null", "null" }, + DEFAULT = { "4", "200", "§§URL§§", "§§URL§§", "GET", "x-pingother" }) + public void preflight_contentTypeWithCharset() throws Exception { + doPreflightTestAllowedMethods("POST, GET, OPTIONS", "text/plain;charset=utf-8"); + } + + /** * Seems that "Access-Control-Allow-Methods" is not considered by FF. * * @throws Exception if the test fails. @@ -188,10 +198,11 @@ @Alerts(IE = { "4", "200", "null", "null", "null", "null" }, DEFAULT = { "4", "200", "§§URL§§", "§§URL§§", "GET", "x-pingother" }) public void preflight_incorrect_methods() throws Exception { - doPreflightTestAllowedMethods(null); + doPreflightTestAllowedMethods(null, "text/plain"); } - private void doPreflightTestAllowedMethods(final String allowedMethods) throws Exception { + private void doPreflightTestAllowedMethods(final String allowedMethods, final String contentType) + throws Exception { expandExpectedAlertsVariables(new URL("http://localhost:" + PORT)); // url without trailing "/" final String html = "<html><head>\n" @@ -202,7 +213,7 @@ + " var url = 'http://' + window.location.hostname + ':" + PORT2 + "/preflight2';\n" + " xhr.open('GET', url, false);\n" + " xhr.setRequestHeader('X-PINGOTHER', 'pingpong');\n" - + " xhr.setRequestHeader('Content-Type' , 'text/plain');" + + " xhr.setRequestHeader('Content-Type' , '" + contentType + "');" + " xhr.send();\n" + " alert(xhr.readyState);\n" + " alert(xhr.status);\n" |