private static boolean isBodilessResponse(HttpResponse response) { int status = response.status().code(); return status == 204 || status == 304 || status / 100 == 1; }
@Override public void proxyWriteFailure(HttpRequest request, HttpResponse response, Throwable cause) { incrementExceptionCounter(cause, response.status()); }
@Override public void proxyingFailure(HttpRequest request, HttpResponse response, Throwable cause) { incrementExceptionCounter(cause, response.status()); }
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()); }
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()); }
/** * 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(); }
@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); }); }
/** * 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); }
@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)); }
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; }
@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; }); }
@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")); }
@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"))); }