本文整理了Java中com.hotels.styx.api.HttpResponse.response()
方法的一些代码示例,展示了HttpResponse.response()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.response()
方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:response
[英]Creates an HTTP response builder with a status of 200 OK and empty body.
[中]创建状态为200 OK且正文为空的HTTP响应生成器。
代码示例来源:origin: HotelsDotCom/styx
@Override
public Map<String, HttpHandler> adminInterfaceHandlers() {
return ImmutableMap.of("status", (request, context) -> Eventual.of(
response(OK)
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.body(format("{ name: \"%s\" status: \"%s\" }", name, status), UTF_8)
.build()
.stream()));
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public LiveHttpResponse doHandle(LiveHttpRequest request) {
return HttpResponse.response(NOT_FOUND)
.body(NOT_FOUND_MESSAGE, UTF_8)
.build()
.stream();
}
}
代码示例来源:origin: HotelsDotCom/styx
private LiveHttpResponse okResponse(String content) {
return HttpResponse.response(OK)
.header(CONTENT_TYPE, PLAIN_TEXT_UTF_8)
.body(content, UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "Charset is not provided.")
public void contentFromStringThrowsNPEWhenCharsetIsNull() {
HttpResponse.response()
.body("Response content.", null, false)
.build();
}
代码示例来源: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: HotelsDotCom/styx
public AppHandler(Origin origin) {
this.origin = origin;
this.standardResponse = HttpResponse.response(OK)
.header(CONTENT_TYPE, HTML_UTF_8.toString())
.body(makeAResponse(origin), UTF_8)
.build();
}
代码示例来源: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 headerValuesAreCaseSensitive() {
HttpResponse response = response(OK).header("Content-Type", "TEXT/PLAIN").build();
assertThat(response.header("content-type"), not(isValue("text/plain")));
}
代码示例来源: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 shouldRemoveContentLengthFromChunkedMessages() {
HttpResponse response = HttpResponse.response().header(CONTENT_LENGTH, 5).build();
HttpResponse chunkedResponse = response.newBuilder().setChunked().build();
assertThat(chunkedResponse.chunked(), is(true));
assertThat(chunkedResponse.header(CONTENT_LENGTH).isPresent(), is(false));
}
代码示例来源:origin: HotelsDotCom/styx
@Override
protected LiveHttpResponse doHandle(LiveHttpRequest request) {
return response(OK)
.disableCaching()
.addHeader(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString())
.body("pong", UTF_8)
.build()
.stream();
}
}
代码示例来源:origin: HotelsDotCom/styx
@Override
protected LiveHttpResponse doHandle(LiveHttpRequest request) {
return response(OK)
.addHeader(CONTENT_TYPE, HTML_UTF_8.toString())
.header(CONTENT_LANGUAGE, "en")
.body(html, UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
private static LiveHttpResponse responseWith(HttpResponseStatus status, String message) {
return HttpResponse.response(status)
.body(message + "\n", UTF_8)
.addHeader(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString())
.disableCaching()
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void addsHeaderValue() {
HttpResponse response = HttpResponse.response()
.header("name", "value1")
.addHeader("name", "value2")
.build();
assertThat(response.headers(), hasItem(header("name", "value1")));
assertThat(response.headers(), hasItem(header("name", "value2")));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void allowsModificationOfBodyBasedOnExistingBody() {
HttpResponse response = HttpResponse.response()
.body("foobar", UTF_8)
.build();
HttpResponse newResponse = response.newBuilder()
.body(response.bodyAs(UTF_8) + "x", UTF_8)
.build();
assertThat(newResponse.bodyAs(UTF_8), is("foobarx"));
}
代码示例来源:origin: HotelsDotCom/styx
@Override
protected LiveHttpResponse doHandle(LiveHttpRequest request) {
return response(OK)
.addHeader(CONTENT_TYPE, JSON_UTF_8.toString())
.disableCaching()
.body(content(isPrettyPrint(request)), UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void canRemoveAHeader() {
Object headerValue = "b";
HttpResponse response = HttpResponse.response()
.header("a", headerValue)
.addHeader("c", headerValue)
.build();
HttpResponse shouldRemoveHeader = response.newBuilder()
.removeHeader("c")
.build();
assertThat(shouldRemoveHeader.headers(), contains(header("a", "b")));
}
代码示例来源: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
@Test
public void removesCookiesInSameBuilder() {
HttpResponse r1 = response()
.addCookies(responseCookie("x", "x1").build())
.removeCookies("x")
.build();
assertThat(r1.cookie("x"), isAbsent());
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void addsCookiesToExistingCookies() {
HttpResponse response = response()
.addCookies(responseCookie("z", "z1").build())
.addCookies(responseCookie("x", "x1").build(), responseCookie("y", "y1").build())
.build();
assertThat(response.cookies(), containsInAnyOrder(responseCookie("x", "x1").build(), responseCookie("y", "y1").build(), responseCookie("z", "z1").build()));
}
内容来源于网络,如有侵权,请联系作者删除!