Search in sources :

Example 6 with Url

use of com.hotels.styx.api.Url in project styx by ExpediaGroup.

the class UrlDecoderTest method decodesOriginForm.

@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.encodedUrl(), 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(""));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Url(com.hotels.styx.api.Url) Test(org.junit.jupiter.api.Test)

Example 7 with Url

use of com.hotels.styx.api.Url in project styx by ExpediaGroup.

the class UrlDecoderTest method decodesAbsoluteForm.

@Test
public void decodesAbsoluteForm() {
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http://example.com/foo");
    Url url = UrlDecoder.decodeUrl(x -> x, request);
    assertThat(url.authority().isPresent(), is(true));
    assertThat(url.path(), is("/foo"));
    assertThat(url.encodedUrl(), is("http://example.com/foo"));
    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"));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Url(com.hotels.styx.api.Url) Test(org.junit.jupiter.api.Test)

Example 8 with Url

use of com.hotels.styx.api.Url in project styx by ExpediaGroup.

the class NettyToStyxRequestDecoder method makeAStyxRequestFrom.

@VisibleForTesting
LiveHttpRequest.Builder makeAStyxRequestFrom(HttpRequest request, Observable<ByteBuf> content) {
    Url url = UrlDecoder.decodeUrl(unwiseCharEncoder, request);
    LiveHttpRequest.Builder requestBuilder = new LiveHttpRequest.Builder().method(toStyxMethod(request.method())).url(url).version(toStyxVersion(request.protocolVersion())).id(uniqueIdSupplier.get()).body(new ByteStream(toPublisher(content.map(Buffers::fromByteBuf))));
    stream(request.headers().spliterator(), false).forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue()));
    return requestBuilder;
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) ByteStream(com.hotels.styx.api.ByteStream) Url(com.hotels.styx.api.Url) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Url (com.hotels.styx.api.Url)8 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)5 Test (org.junit.jupiter.api.Test)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HostAndPort (com.google.common.net.HostAndPort)1 ByteStream (com.hotels.styx.api.ByteStream)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1