public final class HostRequestMatcher extends java.lang.Object implements WebRequestMatcher
An implementation of WebRequestMatcher that allows matching on the host and optionally the port of WebRequest#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 an 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 of 80.
WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com:80");
The above cdnMatcher would match: "http://code.jquery.com/jquery.js" (default port of 80) and "http://code.jquery.com:80/jquery.js". However, it would not match "https://code.jquery.com/jquery.js" (default port of 443).
UrlRegexRequestMatcher
,
DelegatingWebConnection
Constructor and Description |
---|
HostRequestMatcher(java.lang.String... hosts)
Creates a new instance
|
Modifier and Type | Method and Description |
---|---|
boolean |
matches(com.gargoylesoftware.htmlunit.WebRequest request)
Return true if matches on WebRequest, else false
|
public HostRequestMatcher(java.lang.String... hosts)
hosts
- the hosts to match on (i.e. "localhost", "example.com:443")public boolean matches(com.gargoylesoftware.htmlunit.WebRequest request)
WebRequestMatcher
matches
in interface WebRequestMatcher
request
- the WebRequest to attempt to match on