Class HostRequestMatcher
- java.lang.Object
- org.springframework.test.web.servlet.htmlunit.HostRequestMatcher
- All Implemented Interfaces:
WebRequestMatcher
public final class HostRequestMatcher extends Object implements WebRequestMatcher
AWebRequestMatcherthat allows matching on the host and optionally the port ofWebRequest#getUrl().For example, the following would match any request to the host
"code.jquery.com"without regard for the port.WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com");Multiple hosts can also be passed in. For example, the following would match any request to the host
"code.jquery.com"or the host"cdn.com"without regard for the port.WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com", "cdn.com");Alternatively, one can also specify the port. For example, the following would match any request to the host
"code.jquery.com"with the port of80.WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com:80");The above
cdnMatcherwould match"http://code.jquery.com/jquery.js"which has a default port of80and"http://code.jquery.com:80/jquery.js". However, it would not match"https://code.jquery.com/jquery.js"which has a default port of443.- Since:
- 4.2
- Author:
- Rob Winch, Sam Brannen
- See Also:
UrlRegexRequestMatcher,DelegatingWebConnection
Constructor Summary
Constructors Constructor Description HostRequestMatcher(String... hosts)Create a newHostRequestMatcherfor the given hosts — for example:"localhost","example.com:443", etc.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanmatches(com.gargoylesoftware.htmlunit.WebRequest request)Whether this matcher matches on the supplied web request.
Constructor Detail
HostRequestMatcher
public HostRequestMatcher(String... hosts)
Create a newHostRequestMatcherfor the given hosts — for example:"localhost","example.com:443", etc.- Parameters:
hosts- the hosts to match on
Method Detail
matches
public boolean matches(com.gargoylesoftware.htmlunit.WebRequest request)
Description copied from interface:WebRequestMatcherWhether this matcher matches on the supplied web request.- Specified by:
matchesin interfaceWebRequestMatcher- Parameters:
request- theWebRequestto attempt to match on- Returns:
trueif this matcher matches on theWebRequest