本文整理了Java中com.hotels.styx.api.HttpResponse.header()
方法的一些代码示例,展示了HttpResponse.header()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.header()
方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:header
[英]Returns the value of the header with the specified name. If there is more than one header value for the specified header name, the first value is returned.
[中]返回具有指定名称的标头的值。如果指定的头名称有多个头值,则返回第一个值。
代码示例来源:origin: com.hotels.styx/styx-api
/**
* Returns the value of the {@code 'Content-Type'} header.
*
* @return content-type if present
*/
public Optional<String> contentType() {
return header(CONTENT_TYPE);
}
代码示例来源:origin: com.hotels.styx/styx-api
/**
* Returns the value of the {@code 'Content-Length'} header.
*
* @return content-length if present
*/
public Optional<Integer> contentLength() {
return header(CONTENT_LENGTH).map(Integer::valueOf);
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void contentFromStringSetsContentLengthIfRequired() {
HttpResponse response1 = HttpResponse.response()
.body("Response content.", UTF_8, true)
.build();
assertThat(response1.header("Content-Length"), is(Optional.of("17")));
HttpResponse response2 = HttpResponse.response()
.body("Response content.", UTF_8, false)
.build();
assertThat(response2.header("Content-Length"), is(Optional.empty()));
}
代码示例来源: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 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 shouldNotFailToRemoveNonExistentContentLength() {
HttpResponse response = HttpResponse.response().build();
HttpResponse chunkedResponse = response.newBuilder().setChunked().build();
assertThat(chunkedResponse.chunked(), is(true));
assertThat(chunkedResponse.header(CONTENT_LENGTH).isPresent(), is(false));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void supportsCaseInsensitiveHeaderNames() {
HttpResponse response = response(OK).header("Content-Type", "text/plain").build();
assertThat(response.header("content-type"), isValue("text/plain"));
}
代码示例来源: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
@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"));
}
内容来源于网络,如有侵权,请联系作者删除!