public final class HostRequestMatcher extends Object implements WebRequestMatcher
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 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 of 80
.
WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.example:80");
The above cdnMatcher
would match "http://code.jquery.example/jquery.js"
which has a default port of 80
and "http://code.jquery.example:80/jquery.js"
.
However, it would not match "https://code.jquery.example/jquery.js"
which has a default port of 443
.
UrlRegexRequestMatcher
,
DelegatingWebConnection
Constructor and Description |
---|
HostRequestMatcher(String... hosts)
Create a new
HostRequestMatcher for the given hosts —
for example: "localhost" , "example.com:443" , etc. |
Modifier and Type | Method and Description |
---|---|
boolean |
matches(com.gargoylesoftware.htmlunit.WebRequest request)
Whether this matcher matches on the supplied web request.
|
public HostRequestMatcher(String... hosts)
HostRequestMatcher
for the given hosts —
for example: "localhost"
, "example.com:443"
, etc.hosts
- the hosts to match onpublic boolean matches(com.gargoylesoftware.htmlunit.WebRequest request)
WebRequestMatcher
matches
in interface WebRequestMatcher
request
- the WebRequest
to attempt to match ontrue
if this matcher matches on the WebRequest