@Test public void createsResponseWithMinimalInformation() { HttpResponse response = HttpResponse.response() .status(BAD_GATEWAY) .version(HTTP_1_1) .build(); assertThat(response.status(), is(BAD_GATEWAY)); assertThat(response.version(), is(HTTP_1_1)); assertThat(response.cookies(), is(emptyIterable())); assertThat(response.headers(), is(emptyIterable())); assertThat(response.body().length, is(0)); }
private Builder(HttpResponse response) { this.request = response.request; this.status = response.status; headers(response.headers.newBuilder()); this.cookies = new ArrayList<>(response.cookies); version(response.version); body(response.body); }
private HttpResponse(Builder builder) { this.request = builder.request; this.version = builder.version(); this.status = builder.status; this.headers = builder.headers().build(); this.cookies = ImmutableList.copyOf(builder.cookies); this.body = builder.body(); }
@Test public void convertsToStreamingHttpResponse() throws Exception { HttpResponse response = response(CREATED) .version(HTTP_1_1) .header("HeaderName", "HeaderValue") .cookies(responseCookie("CookieName", "CookieValue").build()) .body("message content", UTF_8) .build(); LiveHttpResponse streaming = response.stream(); assertThat(streaming.version(), is(HTTP_1_1)); assertThat(streaming.status(), is(CREATED)); assertThat(streaming.headers(), containsInAnyOrder( header("Content-Length", "15"), header("HeaderName", "HeaderValue"), header("Set-Cookie", "CookieName=CookieValue") )); assertThat(streaming.cookies(), contains(responseCookie("CookieName", "CookieValue").build())); StepVerifier.create(streaming.aggregate(0x100000).map(it -> it.bodyAs(UTF_8))) .expectNext("message content") .verifyComplete(); }
public Builder(FullHttpResponse response, Observable<ByteBuf> body) { this.status = HttpResponseStatus.valueOf(response.status().code()); headers(response.headers().newBuilder()); this.cookies = new ArrayList<>(response.cookies()); version(HttpVersion.valueOf(response.version().toString())); body(body); }