/** * Whether the URL is relative, i.e. not absolute. * * @return true if the URL is relative. * @see {@link #isAbsolute()} */ public boolean isRelative() { return !isAbsolute(); }
/** * Whether the URL is relative, i.e. not absolute. * * @return true if the URL is relative. * @see {@link #isAbsolute()} */ public boolean isRelative() { return !isAbsolute(); }
private static Origin originFromRequest(HttpRequest request) { String hostAndPort = request.header(HOST) .orElseGet(() -> { checkArgument(request.url().isAbsolute(), "host header is not set for request=%s", request); return request.url().authority().map(Url.Authority::hostAndPort) .orElseThrow(() -> new IllegalArgumentException("Cannot send request " + request + " as URL is not absolute and no HOST header is present")); }); return newOriginBuilder(HostAndPort.fromString(hostAndPort)).build(); }
private static Origin originFromRequest(LiveHttpRequest request, Boolean isHttps) { String hostAndPort = request.header(HOST) .orElseGet(() -> { checkArgument(request.url().isAbsolute(), "host header is not set for request=%s", request); return request.url().authority().map(Url.Authority::hostAndPort) .orElseThrow(() -> new IllegalArgumentException("Cannot send request " + request + " as URL is not absolute and no HOST header is present")); }); HostAndPort host = HostAndPort.fromString(hostAndPort); if (host.getPortOrDefault(-1) < 0) { host = host.withDefaultPort(isHttps ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT); } return newOriginBuilder(host.getHostText(), host.getPort()).build(); }
@Test public void identifiesCorrectlyIfUrlIsFullyQualified() throws Exception { Url fqUrl = url("http://example.com").build(); assertThat(fqUrl.isFullyQualified(), is(true)); assertThat(fqUrl.isAbsolute(), is(false)); assertThat(fqUrl.isRelative(), is(true)); Url nonFqUrl = url("/somepath").build(); assertThat(nonFqUrl.isFullyQualified(), is(false)); assertThat(nonFqUrl.isAbsolute(), is(true)); assertThat(nonFqUrl.isRelative(), is(false)); }