From: <rb...@us...> - 2017-11-14 17:41:17
|
Revision: 14948 http://sourceforge.net/p/htmlunit/code/14948 Author: rbri Date: 2017-11-14 17:41:14 +0000 (Tue, 14 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -163,7 +163,7 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}; + HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +182,7 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,7 +198,7 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection", + HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection", "Cookie"}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; @@ -226,7 +226,7 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; + HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -49,6 +49,16 @@ /** accept-encoding. */ public static final String ACCEPT_ENCODING_LC = "accept-encoding"; + /** User-Agent. */ + public static final String USER_AGENT = "User-Agent"; + /** user-agent. */ + public static final String USER_AGENT_LC = "user-agent"; + + /** Host. */ + public static final String HOST = "Host"; + /** host. */ + public static final String HOST_LC = "host"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -779,10 +779,10 @@ final String[] headerNames = webClient_.getBrowserVersion().getHeaderNamesOrdered(); if (headerNames != null) { for (final String header : headerNames) { - if ("Host".equals(header)) { + if (HttpHeader.HOST.equals(header)) { list.add(new HostHeaderHttpRequestInterceptor(host.toString())); } - else if ("User-Agent".equals(header)) { + else if (HttpHeader.USER_AGENT.equals(header)) { list.add(new UserAgentHeaderHttpRequestInterceptor(userAgent)); } else if (HttpHeader.ACCEPT.equals(header) && requestHeaders.get(header) != null) { @@ -839,7 +839,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("Host", value_); + request.setHeader(HttpHeader.HOST, value_); } } @@ -852,7 +852,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("User-Agent", value_); + request.setHeader(HttpHeader.USER_AGENT, value_); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -95,7 +95,7 @@ // connection.setUseCaches(false); connection.setConnectTimeout(webClient_.getOptions().getTimeout()); - connection.addRequestProperty("User-Agent", webClient_.getBrowserVersion().getUserAgent()); + connection.addRequestProperty(HttpHeader.USER_AGENT, webClient_.getBrowserVersion().getUserAgent()); connection.setInstanceFollowRedirects(false); // copy the headers from WebRequestSettings 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-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -110,8 +110,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", - "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", - "user-agent", "via"); + HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", + HttpHeader.USER_AGENT_LC, "via"); private int state_ = STATE_UNSENT; private Function stateChangeHandler_; 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-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -135,8 +135,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", - "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", - "upgrade", "user-agent", "via"); + HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", + "upgrade", HttpHeader.USER_AGENT_LC, "via"); private int state_; private Function stateChangeHandler_; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -44,17 +44,19 @@ provider.addCredentials("username", "password"); UsernamePasswordCredentials credentials = - (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("username", credentials.getUserName()); assertEquals("password", credentials.getPassword()); provider.addCredentials("username", "new password"); - credentials = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + credentials = (UsernamePasswordCredentials) provider + .getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("username", credentials.getUserName()); assertEquals("new password", credentials.getPassword()); provider.addCredentials("new username", "other password"); - credentials = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + credentials = (UsernamePasswordCredentials) provider + .getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("new username", credentials.getUserName()); assertEquals("other password", credentials.getPassword()); } @@ -82,16 +84,17 @@ final String scheme = new BasicScheme().getSchemeName(); final DefaultCredentialsProvider provider = new DefaultCredentialsProvider(); - provider.addCredentials("username", "password", "host", 80, realm); + provider.addCredentials("username", "password", HttpHeader.HOST_LC, 80, realm); UsernamePasswordCredentials credentials = - (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("username", credentials.getUserName()); assertEquals("password", credentials.getPassword()); - provider.removeCredentials(new AuthScope("host", 80, realm, scheme)); + provider.removeCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); - credentials = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + credentials = (UsernamePasswordCredentials) provider + .getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertNull(credentials); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -223,7 +223,7 @@ if (caseInsensitiveHeaders.contains(headerNameLower)) { sb.append(headerEntry.getValue().toLowerCase(Locale.ROOT)); } - else if ("user-agent".equals(headerNameLower)) { + else if (HttpHeader.USER_AGENT_LC.equals(headerNameLower)) { // ignore the 64bit difference sb.append(headerEntry.getValue().replace("WOW64; ", "")); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -47,14 +47,14 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", + @Alerts(CHROME = {HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE}, - FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, "Connection"}, - FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, - "Connection", "Upgrade-Insecure-Requests"}, - IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", - HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection"}) + FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, "Connection", "Upgrade-Insecure-Requests"}, + IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, + HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection"}) @NotYetImplemented(IE) public void headers() throws Exception { final String response = "HTTP/1.1 200 OK\r\n" @@ -92,15 +92,16 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", + @Alerts(CHROME = {HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}, - FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, - HttpHeader.REFERER, "Cookie", "Connection"}, - FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, - HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}, - IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", - HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection", "Cookie"}) + FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}, + FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", + "Upgrade-Insecure-Requests"}, + IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, + HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -351,7 +351,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "Host", + @Alerts(DEFAULT = HttpHeader.HOST, IE = {}) public void hostHeaderFirst() throws Exception { final Logger logger = Logger.getLogger("org.apache.http.headers"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -1180,7 +1180,7 @@ assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); - assertEquals(expectedHeaders[3], "" + headers.get("Host")); + assertEquals(expectedHeaders[3], "" + headers.get(HttpHeader.HOST)); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } } @@ -1216,7 +1216,7 @@ assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); - assertEquals(expectedHeaders[3], "" + headers.get("Host")); + assertEquals(expectedHeaders[3], "" + headers.get(HttpHeader.HOST)); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -1289,8 +1289,9 @@ final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", - "expect", "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", - "user-agent", "via" }; + "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, + "te", "trailer", "transfer-encoding", "upgrade", + HttpHeader.USER_AGENT_LC, "via" }; for (final String header : headers) { assertFalse(XMLHttpRequest.isAuthorizedHeader(header)); assertFalse(XMLHttpRequest.isAuthorizedHeader(header.toUpperCase(Locale.ROOT))); |