From: <rb...@us...> - 2017-12-01 08:42:54
|
Revision: 14985 http://sourceforge.net/p/htmlunit/code/14985 Author: rbri Date: 2017-12-01 08:42:51 +0000 (Fri, 01 Dec 2017) Log Message: ----------- cleanup Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-12-01 08:40:03 UTC (rev 14984) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-12-01 08:42:51 UTC (rev 14985) @@ -88,6 +88,23 @@ /** Upgrade-Insecure-Requests. */ public static final String UPGRADE_INSECURE_REQUESTS = "Upgrade-Insecure-Requests"; + /** Access-Control-Request-Method. */ + public static final String ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method"; + /** Access-Control-Request-Headers. */ + public static final String ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers"; + /** Access-Control-Allow-Origin. */ + public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; + /** Access-Control-Allow-Credentials. */ + public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials"; + /** Access-Control-Allow-Headers. */ + public static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"; + + /** Ping-From. */ + public static final String PING_FROM = "Ping-From"; + + /** Ping-From. */ + public static final String PING_TO = "Ping-To"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-12-01 08:40:03 UTC (rev 14984) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-12-01 08:42:51 UTC (rev 14985) @@ -96,11 +96,6 @@ private static final char REQUEST_HEADERS_SEPARATOR = ','; - private static final String HEADER_ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method"; - private static final String HEADER_ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers"; - private static final String HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; - private static final String HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"; - private static final String ALLOW_ORIGIN_ALL = "*"; private static final String[] ALL_PROPERTIES_ = {"onreadystatechange", "readyState", "responseText", "responseXML", @@ -541,7 +536,7 @@ // header request-method preflightRequest.setAdditionalHeader( - HEADER_ACCESS_CONTROL_REQUEST_METHOD, + HttpHeader.ACCESS_CONTROL_REQUEST_METHOD, webRequest_.getHttpMethod().name()); // header request-headers @@ -555,7 +550,7 @@ builder.append(name); } } - preflightRequest.setAdditionalHeader(HEADER_ACCESS_CONTROL_REQUEST_HEADERS, builder.toString()); + preflightRequest.setAdditionalHeader(HttpHeader.ACCESS_CONTROL_REQUEST_HEADERS, builder.toString()); // do the preflight request final WebResponse preflightResponse = wc.loadWebResponse(preflightRequest); @@ -577,7 +572,7 @@ } boolean allowOriginResponse = true; if (originHeaderValue != null) { - final String value = webResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN); + final String value = webResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN); allowOriginResponse = originHeaderValue.equals(value); allowOriginResponse = allowOriginResponse || ALLOW_ORIGIN_ALL.equals(value); } @@ -624,12 +619,12 @@ } private boolean isPreflightAuthorized(final WebResponse preflightResponse) { - final String originHeader = preflightResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN); + final String originHeader = preflightResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN); if (!ALLOW_ORIGIN_ALL.equals(originHeader) && !webRequest_.getAdditionalHeaders().get(HttpHeader.ORIGIN).equals(originHeader)) { return false; } - String headersHeader = preflightResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_HEADERS); + String headersHeader = preflightResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_HEADERS); if (headersHeader == null) { headersHeader = ""; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java 2017-12-01 08:40:03 UTC (rev 14984) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java 2017-12-01 08:42:51 UTC (rev 14985) @@ -156,8 +156,8 @@ if (ATTRIBUTE_NOT_DEFINED != getPingAttribute() && browser.hasFeature(ANCHOR_IGNORE_TARGET_FOR_JS_HREF)) { final URL pingUrl = getTargetUrl(getPingAttribute(), page); final WebRequest pingRequest = new WebRequest(pingUrl, HttpMethod.POST); - pingRequest.setAdditionalHeader("Ping-From", page.getUrl().toExternalForm()); - pingRequest.setAdditionalHeader("Ping-To", url.toExternalForm()); + pingRequest.setAdditionalHeader(HttpHeader.PING_FROM, page.getUrl().toExternalForm()); + pingRequest.setAdditionalHeader(HttpHeader.PING_TO, url.toExternalForm()); pingRequest.setRequestBody("PING"); page.getWebClient().loadWebResponse(pingRequest); } 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 2017-12-01 08:40:03 UTC (rev 14984) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-12-01 08:42:51 UTC (rev 14985) @@ -120,12 +120,6 @@ @JsxConstant public static final int DONE = 4; - private static final String HEADER_ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method"; - private static final String HEADER_ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers"; - private static final String HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; - private static final String HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials"; - private static final String HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"; - private static final String ALLOW_ORIGIN_ALL = "*"; private static final String[] ALL_PROPERTIES_ = {"onreadystatechange", "readyState", "responseText", "responseXML", @@ -718,7 +712,7 @@ // header request-method preflightRequest.setAdditionalHeader( - HEADER_ACCESS_CONTROL_REQUEST_METHOD, + HttpHeader.ACCESS_CONTROL_REQUEST_METHOD, webRequest_.getHttpMethod().name()); // header request-headers @@ -733,7 +727,7 @@ builder.append(name); } } - preflightRequest.setAdditionalHeader(HEADER_ACCESS_CONTROL_REQUEST_HEADERS, builder.toString()); + preflightRequest.setAdditionalHeader(HttpHeader.ACCESS_CONTROL_REQUEST_HEADERS, builder.toString()); // do the preflight request final WebResponse preflightResponse = wc.loadWebResponse(preflightRequest); @@ -755,7 +749,7 @@ } boolean allowOriginResponse = true; if (originHeaderValue != null) { - String value = webResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN); + String value = webResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN); allowOriginResponse = originHeaderValue.equals(value); if (isWithCredentials()) { allowOriginResponse = allowOriginResponse @@ -763,7 +757,7 @@ && ALLOW_ORIGIN_ALL.equals(value)); // second step: check the allow-credentials header for true - value = webResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS); + value = webResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_CREDENTIALS); allowOriginResponse = allowOriginResponse && Boolean.parseBoolean(value); } else { @@ -847,12 +841,12 @@ } private boolean isPreflightAuthorized(final WebResponse preflightResponse) { - final String originHeader = preflightResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN); + final String originHeader = preflightResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN); if (!ALLOW_ORIGIN_ALL.equals(originHeader) && !webRequest_.getAdditionalHeaders().get(HttpHeader.ORIGIN).equals(originHeader)) { return false; } - String headersHeader = preflightResponse.getResponseHeaderValue(HEADER_ACCESS_CONTROL_ALLOW_HEADERS); + String headersHeader = preflightResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_HEADERS); if (headersHeader == null) { headersHeader = ""; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java 2017-12-01 08:40:03 UTC (rev 14984) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java 2017-12-01 08:42:51 UTC (rev 14985) @@ -977,8 +977,8 @@ secondString = null; body = null; } - assertEquals(firstString, PingServlet.HEADERS_.get("Ping-From")); - assertEquals(secondString, PingServlet.HEADERS_.get("Ping-To")); + assertEquals(firstString, PingServlet.HEADERS_.get(HttpHeader.PING_FROM)); + assertEquals(secondString, PingServlet.HEADERS_.get(HttpHeader.PING_TO)); assertEquals(body, PingServlet.BODY_); } |