本文整理了Java中com.hotels.styx.api.HttpResponse.status()
方法的一些代码示例,展示了HttpResponse.status()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.status()
方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:status
暂无
代码示例来源:origin: com.hotels.styx/styx-client
private static boolean isBodilessResponse(HttpResponse response) {
int status = response.status().code();
return status == 204 || status == 304 || status / 100 == 1;
}
代码示例来源:origin: com.hotels.styx/styx-client
private void recordErrorStatusMetrics(HttpResponse response) {
if (isError(response.status())) {
metricsRegistry.counter("origins.response.status." + response.status().code()).inc();
}
}
代码示例来源:origin: com.hotels.styx/styx-api
@Override
public void proxyWriteFailure(HttpRequest request, HttpResponse response, Throwable cause) {
incrementExceptionCounter(cause, response.status());
}
代码示例来源:origin: com.hotels.styx/styx-api
@Override
public void proxyingFailure(HttpRequest request, HttpResponse response, Throwable cause) {
incrementExceptionCounter(cause, response.status());
}
代码示例来源: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
/**
* 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: 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
/**
* Creates a new {@link Builder} object from a response code and a content stream.
* <p>
* Builder's response status line parameters and the HTTP headers are populated from
* the given {@code response} object, but the content stream is set to {@code ByteStream}.
*
* @param response a full response for which the builder is based on
* @param byteStream a content byte stream
*/
public Builder(HttpResponse response, ByteStream byteStream) {
this.status = statusWithCode(response.status().code());
this.version = httpVersion(response.version().toString());
this.headers = response.headers().newBuilder();
this.body = requireNonNull(byteStream);
}
代码示例来源: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
@Override
public void check(HttpClient client, Origin origin, OriginHealthCheckFunction.Callback responseCallback) {
HttpRequest request = newHealthCheckRequestFor(origin);
client.sendRequest(request)
.handle((response, cause) -> {
if (response != null) {
if (response.status().equals(OK)) {
responseCallback.originStateResponse(HEALTHY);
} else {
meterCache.get(origin).mark();
responseCallback.originStateResponse(UNHEALTHY);
}
} else if (cause != null) {
meterCache.get(origin).mark();
responseCallback.originStateResponse(UNHEALTHY);
}
return null;
});
}
代码示例来源:origin: HotelsDotCom/styx
@Test
public void respondsWithStaticBody() {
StaticBodyHttpHandler handler = new StaticBodyHttpHandler(PLAIN_TEXT_UTF_8, "foo", UTF_8);
LiveHttpResponse response = Mono.from(handler.handle(get("/").build(), HttpInterceptorContext.create())).block();
HttpResponse fullResponse = Mono.from(response.aggregate(1024)).block();
assertThat(fullResponse.status(), is(OK));
assertThat(fullResponse.contentType(), isValue(PLAIN_TEXT_UTF_8.toString()));
assertThat(fullResponse.contentLength(), isValue(length("foo")));
assertThat(fullResponse.bodyAs(UTF_8), is("foo"));
}
代码示例来源: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")));
}
内容来源于网络,如有侵权,请联系作者删除!