本文整理了Java中com.hotels.styx.api.HttpResponse.body()
方法的一些代码示例,展示了HttpResponse.body()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.body()
方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:body
[英]Return the body of the response.
[中]返回响应的主体。
代码示例来源:origin: HotelsDotCom/styx
@Test
public void responseBodyIsImmutable() {
HttpResponse response = response(OK)
.body("Original body", UTF_8)
.build();
response.body()[0] = 'A';
assertThat(response.bodyAs(UTF_8), is("Original body"));
}
代码示例来源:origin: HotelsDotCom/styx
@Test(dataProvider = "emptyBodyResponses")
public void encodesToFullHttpResponseWithEmptyBody(LiveHttpResponse response) throws Exception {
HttpResponse full = Mono.from(response.aggregate(0x1000)).block();
assertThat(full.body(), is(new byte[0]));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void allowsModificationOfHeadersBasedOnBody() {
HttpResponse response = HttpResponse.response()
.body("foobar", UTF_8)
.build();
assertThat(response.header("some-header"), isAbsent());
HttpResponse newResponse = response.newBuilder()
.header("some-header", response.body().length)
.build();
assertThat(newResponse.header("some-header"), isValue("6"));
assertThat(newResponse.bodyAs(UTF_8), is("foobar"));
}
代码示例来源:origin: HotelsDotCom/styx
/**
* Creates a new {@link Builder} object from an existing {@link LiveHttpResponse} object.
* Similar to {@link this.newBuilder} method.
*
* @param response a full HTTP response instance
*/
public Builder(HttpResponse response) {
this.status = response.status();
this.version = response.version();
this.headers = response.headers().newBuilder();
this.body = response.body();
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void contentFromByteArraySetsContentLengthIfRequired() {
HttpResponse response1 = HttpResponse.response()
.body("Response content.".getBytes(UTF_16), true)
.build();
assertThat(response1.body(), is("Response content.".getBytes(UTF_16)));
assertThat(response1.header("Content-Length"), is(Optional.of("36")));
HttpResponse response2 = HttpResponse.response()
.body("Response content.".getBytes(UTF_8), false)
.build();
assertThat(response2.body(), is("Response content.".getBytes(UTF_8)));
assertThat(response2.header("Content-Length"), is(Optional.empty()));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void encodesBodyWithGivenCharset() {
HttpResponse response = HttpResponse.response()
.body("Response content.", UTF_16, true)
.build();
assertThat(response.body().length, is(36));
}
代码示例来源:origin: com.hotels.styx/styx-client
@Override
public void check(Origin origin, OriginHealthCheckFunction.Callback responseCallback) {
HttpRequest request = newHealthCheckRequestFor(origin);
client.sendRequest(request).subscribe(response -> {
if (response.status().equals(OK)) {
responseCallback.originStateResponse(HEALTHY);
} else {
meterCache.get(origin).mark();
responseCallback.originStateResponse(UNHEALTHY);
}
response.body().content().subscribe(RELEASE_BUFFER);
}, error -> {
meterCache.get(origin).mark();
responseCallback.originStateResponse(UNHEALTHY);
});
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void createsAResponseWithDefaultValues() {
HttpResponse response = HttpResponse.response().build();
assertThat(response.version(), is(HTTP_1_1));
assertThat(response.cookies(), is(emptyIterable()));
assertThat(response.headers(), is(emptyIterable()));
assertThat(response.body().length, is(0));
}
代码示例来源:origin: HotelsDotCom/styx
@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));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void transformsBody() throws ExecutionException, InterruptedException {
Buffer buffer = new Buffer("I'm going to get removed.", UTF_8);
LiveHttpResponse response = response(NO_CONTENT)
.body(new ByteStream(Flux.just(buffer)))
.build();
HttpResponse fullResponse = Mono.from(response.newBuilder()
.body(ByteStream::drop)
.build()
.aggregate(1000)).block();
assertThat(fullResponse.body().length, is(0));
assertThat(buffer.delegate().refCnt(), is(0));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void encodesToFullHttpResponse() {
LiveHttpResponse response = response(CREATED)
.version(HTTP_1_0)
.header("HeaderName", "HeaderValue")
.cookies(responseCookie("CookieName", "CookieValue").build())
.body(new ByteStream(Flux.just("foo", "bar").map(it -> new Buffer(copiedBuffer(it, UTF_8)))))
.build();
HttpResponse full = Mono.from(response.aggregate(0x1000)).block();
assertThat(full.status(), is(CREATED));
assertThat(full.version(), is(HTTP_1_0));
assertThat(full.headers(), containsInAnyOrder(header("HeaderName", "HeaderValue"), header("Set-Cookie", "CookieName=CookieValue")));
assertThat(full.cookies(), contains(responseCookie("CookieName", "CookieValue").build()));
assertThat(full.body(), is(bytes("foobar")));
}
内容来源于网络,如有侵权,请联系作者删除!