/** * Creates a new {@link Builder} object with specified and URI. * * @param method a HTTP method * @param uri URI */ public Builder(HttpMethod method, String uri) { this(); this.method = requireNonNull(method); this.url = Url.Builder.url(uri).build(); }
@Test public void exposesDecodedPath() throws Exception { Url url = Url.Builder.url("http://localhost/foo%20bar").build(); assertThat(url.toURI().getPath(), is("/foo bar")); }
@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)); }
@Test public void authorityReturnsHostAndPortStringWithoutPort() { Url.Authority authority = url("http://example.com") .build().authority().get(); assertThat(authority.hostAndPort(), is("example.com")); }
@Test public void authorityReturnsHostAndPortStringWithPort() { Url.Authority authority = url("http://example.com:8080") .build().authority().get(); assertThat(authority.hostAndPort(), is("example.com:8080")); }
@Test public void decodesQueryParamsWithMultipleValues() { Url url = url("http://example.com?foo=bar&foo=hello") .build(); assertThat(url.queryParams("foo"), containsInAnyOrder("bar", "hello")); }
@Test public void decodesQueryParamsContainingEncodedEquals() { Url url = url("http://example.com/?foo=a%2Bb%3Dc") .build(); assertThat(url.queryParam("foo"), isValue("a+b=c")); }
@Test public void createARequestWithFullUrl() { HttpRequest request = get("http://www.hotels.com").build(); assertThat(request.url(), is(url("http://www.hotels.com").build())); }
public Builder() { this.url = Url.Builder.url("/").build(); this.headers = new HttpHeaders.Builder(); this.body = Observable.empty(); this.cookies = new ArrayList<>(); }
@Test public void absentPortIsStoredInAuthorityAsMinusOne() throws Exception { int port = url("http://example.com") .build().authority().get().port(); assertThat(port, is(-1)); }
@Test public void portNumberIsStoredInAuthority() throws Exception { int port = url("http://ecom.com:8080") .build().authority().get().port(); assertThat(port, is(8080)); }
@Test public void extractsTheHostUrl() throws Exception { Optional<String> host = url("http://ecom.com").build().host(); assertThat(host, isValue("ecom.com")); }
@Test public void canDropThePath() throws Exception { Url fqUrl = url("/landing/de3445") .authority("example.com") .build(); Url newUrl = fqUrl.newBuilder() .dropHost() .build(); assertThat(newUrl.authority(), isAbsent()); assertThat(newUrl.toString(), is("/landing/de3445")); }
/** * Sets the request URI. * * @param uri URI * @return {@code this} */ public Builder uri(String uri) { return this.url(Url.Builder.url(uri).build()); }
public Builder(HttpMethod method, String uri) { this(); this.method = requireNonNull(method); this.url = Url.Builder.url(uri).build(); this.secure = url.isSecure(); }
@Test public void createARequestWithStreamingUrl() { LiveHttpRequest request = get("http://www.hotels.com").build(); assertThat(request.url(), is(url("http://www.hotels.com").build())); }
@Test(dataProvider = "pathSegmentAllowedChars") public void shouldNotEncodeAllowedCharactersInPath(String character) { String path = "/customercare/subscribe.html" + character + "sessid=nXF5jQ8rTW3bAbh6djb2hYJE3D.web-app-02"; assertThat(url(path).build().encodedUri(), is(path)); } @Test
/** * Creates a new {@link Builder} object with default attributes. */ public Builder() { this.url = Url.Builder.url("/").build(); this.headers = new HttpHeaders.Builder(); this.body = new ByteStream(Flux.empty()); }
/** * Sets the request URI. * * @param uri URI * @return {@code this} */ public Builder uri(String uri) { return this.url(Url.Builder.url(uri).build()); }
public Builder(HttpMethod method, String uri) { this(); this.method = requireNonNull(method); this.url = Url.Builder.url(uri).build(); this.secure = url.isSecure(); }