本文整理了Java中com.hotels.styx.api.HttpResponse.cookies()
方法的一些代码示例,展示了HttpResponse.cookies()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.cookies()
方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:cookies
[英]Return all cookies in this response.
[中]返回此响应中的所有cookie。
代码示例来源:origin: HotelsDotCom/styx
/**
* Decodes the "Set-Cookie" headers in this response and returns the specified cookie.
*
* @param name cookie name
* @return an optional cookie
*/
public Optional<ResponseCookie> cookie(String name) {
return cookies().stream()
.filter(cookie -> cookie.name().equals(name))
.findFirst();
}
代码示例来源:origin: com.hotels.styx/styx-api
public Builder(HttpResponse response, byte[] encodedBody) {
this.status = statusWithCode(response.status().code());
this.version = httpVersion(response.version().toString());
this.headers = response.headers().newBuilder();
this.body = encodedBody;
this.cookies = new ArrayList<>(response.cookies());
}
代码示例来源:origin: com.hotels.styx/styx-api
public Builder(HttpResponse response, Observable<ByteBuf> decoded) {
this.status = statusWithCode(response.status().code());
this.version = httpVersion(response.version().toString());
this.headers = response.headers().newBuilder();
this.body = decoded;
this.cookies = new ArrayList<>(response.cookies());
}
代码示例来源: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: com.hotels.styx/styx-common
private static Info information(HttpResponse response, boolean longFormatEnabled) {
Info info = new Info()
.add("status", response.status());
if (longFormatEnabled) {
info.add("headers", response.headers())
.add("cookies", response.cookies());
}
return info;
}
代码示例来源: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")));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void addsCookies() {
HttpResponse response = response()
.addCookies(responseCookie("x", "x1").build(), responseCookie("y", "y1").build())
.build();
assertThat(response.cookies(), containsInAnyOrder(responseCookie("x", "x1").build(), responseCookie("y", "y1").build()));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void setsMultipleOutboundCookies() {
HttpResponse response = HttpResponse.response()
.cookies(
responseCookie("a", "b").build(),
responseCookie("c", "d").build())
.build();
Set<ResponseCookie> cookies = response.cookies();
assertThat(cookies, containsInAnyOrder(
responseCookie("a", "b").build(),
responseCookie("c", "d").build()
));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void newCookiesWithDuplicateNamesOverridePreviousOnes() {
HttpResponse r1 = response()
.cookies(responseCookie("y", "y1").build())
.build();
HttpResponse r2 = r1.newBuilder().addCookies(
responseCookie("y", "y2").build())
.build();
assertThat(r2.cookies(), containsInAnyOrder(responseCookie("y", "y2").build()));
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void removesCookies() {
HttpResponse r1 = response()
.addCookies(responseCookie("x", "x1").build(), responseCookie("y", "y1").build())
.build();
HttpResponse r2 = r1.newBuilder()
.removeCookies("x")
.removeCookies("foo") // ensure that trying to remove a non-existent cookie does not cause Exception
.build();
assertThat(r2.cookies(), contains(responseCookie("y", "y1").build()));
}
代码示例来源: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()));
}
内容来源于网络,如有侵权,请联系作者删除!