/** * Return the encoded url string. * * @return the encoded url string */ public String encodedUri() { return toString(); }
/** * Return the encoded url string. * * @return the encoded url string */ public String encodedUri() { return toString(); }
/** * Convert this object to the {@link URI} class from the java standard library. * * @return a {@link URI} */ public URI toURI() { try { return new URI(toString()); } catch (URISyntaxException e) { throw propagate(e); } }
/** * Convert this object to the {@link URI} class from the java standard library. * * @return a {@link URI} */ public URI toURI() { try { return new URI(toString()); } catch (URISyntaxException e) { throw propagate(e); } }
@VisibleForTesting static DefaultHttpRequest toNettyRequest(HttpRequest request) { DefaultHttpRequest nettyRequest = new DefaultHttpRequest(request.version(), request.method(), request.url().toString(), false); request.headers().forEach((name, value) -> nettyRequest.headers().add(name, value)); Cookie[] cookies = request.cookies().stream() .map(HttpRequestOperation::styxCookieToNettyCookie) .toArray(Cookie[]::new); if (cookies.length > 0) { nettyRequest.headers().set(COOKIE, ClientCookieEncoder.LAX.encode(cookies)); } return nettyRequest; }
@VisibleForTesting static DefaultHttpRequest toNettyRequest(LiveHttpRequest request) { HttpVersion version = request.version(); HttpMethod method = request.method(); String url = request.url().toString(); DefaultHttpRequest nettyRequest = new DefaultHttpRequest(toNettyVersion(version), toNettyMethod(method), url, false); request.headers().forEach((name, value) -> nettyRequest.headers().add(name, value)); return nettyRequest; }
@Test public void shouldCreateAValidUrlIfAuthorityIsMissing() { Url url = new Url.Builder() .scheme("https") .path("/") .build(); assertThat(url.toString(), is("/")); }
@Test public void shouldCreateWithSchemeAndHost() throws CharacterCodingException { assertThat("http://example.com", is(new Url.Builder() .scheme("http") .authority("example.com") .path("") .build() .toString())); }
@Test public void shouldCreateWithHostAndPort() throws CharacterCodingException { assertThat("http://example.com:8080", is(new Url.Builder() .scheme("http") .authority(authority("example.com", 8080)) .build() .toString())); }
@Test public void shouldCreateWithUserAndHostAndPort() throws CharacterCodingException { assertThat("http://someone@example.com:8080", is(new Url.Builder() .scheme("http") .authority(authority("someone", "example.com", 8080)) .build() .toString())); }
@Test public void shouldCreateWithPath() throws CharacterCodingException { Url url = new Url.Builder() .scheme("http") .authority("example.com") .path("/landing/de3445") .build(); assertThat(url.toString(), is("http://example.com/landing/de3445")); }
@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")); }
@Test public void createsARequestWithDefaultValues() { HttpRequest request = get("/index").build(); assertThat(request.version(), is(HTTP_1_1)); assertThat(request.url().toString(), is("/index")); assertThat(request.path(), is("/index")); assertThat(request.id(), is(notNullValue())); assertThat(request.cookies(), is(emptyIterable())); assertThat(request.headers(), is(emptyIterable())); assertThat(request.headers("any"), is(emptyIterable())); assertThat(request.body().length, is(0)); assertThat(request.cookie("any"), isAbsent()); assertThat(request.header("any"), isAbsent()); assertThat(request.keepAlive(), is(true)); assertThat(request.method(), is(GET)); assertThat(request.queryParam("any"), isAbsent()); assertThat(request.queryParams("any"), is(emptyIterable())); }
@Test public void createsARequestWithDefaultValues() { LiveHttpRequest request = get("/index").build(); assertThat(request.version(), is(HTTP_1_1)); assertThat(request.url().toString(), is("/index")); assertThat(request.path(), is("/index")); assertThat(request.id(), is(notNullValue())); assertThat(request.cookies(), is(emptyIterable())); assertThat(request.headers(), is(emptyIterable())); assertThat(request.headers("any"), is(emptyIterable())); assertThat(bytesToString(request.body()), is("")); assertThat(request.cookie("any"), isAbsent()); assertThat(request.header("any"), isAbsent()); assertThat(request.keepAlive(), is(true)); assertThat(request.method(), is(GET)); assertThat(request.queryParam("any"), isAbsent()); assertThat(request.queryParams("any"), is(emptyIterable())); }
private FormData toFormData(ByteBuf byteBuf) { HttpPostRequestDecoder postRequestDecoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(false), new DefaultHttpRequest(version, method, url.toString())); postRequestDecoder.offer(new DefaultHttpContent(byteBuf)); postRequestDecoder.offer(new DefaultLastHttpContent()); return new FormData(postRequestDecoder); }