### Question:
UrlDecoder { static Url decodeUrl(UnwiseCharsEncoder unwiseCharEncoder, HttpRequest request) { String host = request.headers().get(HOST); if (request.uri().startsWith("/") && host != null) { URI uri = URI.create("http: return new Url.Builder() .path(uri.getRawPath()) .rawQuery(uri.getRawQuery()) .fragment(uri.getFragment()) .build(); } else { return url(unwiseCharEncoder.encode(request.uri())).build(); } } private  UrlDecoder();   }### Answer:
@Test public void decodesOriginForm() { DefaultFullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/foo"); request.headers().add(HOST, "example.com"); Url url = UrlDecoder.decodeUrl(x -> x, request); assertThat(url.authority(), is(Optional.empty())); assertThat(url.path(), is("/foo")); assertThat(url.encodedUri(), is("/foo")); assertThat(url.isAbsolute(), is(false)); assertThat(url.isRelative(), is(true)); assertThat(url.host(), is(Optional.empty())); assertThat(url.queryParams(), is(emptyMap())); assertThat(url.scheme(), is("")); }
@Test public void exposesPathComponentsWithDoubleSlashSeparators() { DefaultFullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, " request.headers().add(HOST, "example.com"); Url url = UrlDecoder.decodeUrl(x -> x, request); assertThat(url.authority(), is(Optional.empty())); assertThat(url.path(), is(" assertThat(url.encodedUri(), is(" assertThat(url.isAbsolute(), is(false)); assertThat(url.isRelative(), is(true)); assertThat(url.host(), is(Optional.empty())); assertThat(url.queryParams(), is(emptyMap())); assertThat(url.scheme(), is("")); }
@Test public void decodesOriginFormWithUppercaseHostHeader() { DefaultFullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/foo"); request.headers().add("HOST", "example.com"); Url url = UrlDecoder.decodeUrl(x -> x, request); assertThat(url.authority(), is(Optional.empty())); assertThat(url.path(), is("/foo")); assertThat(url.encodedUri(), is("/foo")); assertThat(url.isAbsolute(), is(false)); assertThat(url.isRelative(), is(true)); assertThat(url.host(), is(Optional.empty())); assertThat(url.queryParams(), is(emptyMap())); assertThat(url.scheme(), is("")); }
@Test public void decodesAbsoluteForm() { DefaultFullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http: Url url = UrlDecoder.decodeUrl(x -> x, request); assertThat(url.authority().isPresent(), is(true)); assertThat(url.path(), is("/foo")); assertThat(url.encodedUri(), is("http: assertThat(url.isAbsolute(), is(true)); assertThat(url.isRelative(), is(false)); assertThat(url.host(), is(Optional.of("example.com"))); assertThat(url.queryParams(), is(emptyMap())); assertThat(url.scheme(), is("http")); }