use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project reactor-netty by reactor.
the class HttpClientWithTomcatTest method simpleClientPooling.
@Test
void simpleClientPooling() {
ConnectionProvider p = ConnectionProvider.create("simpleClientPooling", 1);
AtomicReference<Channel> ch1 = new AtomicReference<>();
AtomicReference<Channel> ch2 = new AtomicReference<>();
HttpResponseStatus r = HttpClient.create(p).doOnResponse((res, c) -> ch1.set(c.channel())).wiretap(true).get().uri(getURL() + "/status/404").responseSingle((res, buf) -> buf.thenReturn(res.status())).block(Duration.ofSeconds(30));
HttpClient.create(p).doOnResponse((res, c) -> ch2.set(c.channel())).wiretap(true).get().uri(getURL() + "/status/404").responseSingle((res, buf) -> buf.thenReturn(res.status())).block(Duration.ofSeconds(30));
AtomicBoolean same = new AtomicBoolean();
same.set(ch1.get() == ch2.get());
assertThat(same.get()).isTrue();
assertThat(r).isEqualTo(HttpResponseStatus.NOT_FOUND);
p.dispose();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project reactor-netty by reactor.
the class HttpRedirectTest method redirect_issuesOnRequestForEachAttempt.
/**
* This ensures functionality such as metrics and tracing can accurately count requests.
*/
@Test
void redirect_issuesOnRequestForEachAttempt() {
disposableServer = createServer().host("localhost").route(r -> r.get("/1", (req, res) -> res.sendRedirect("/3")).get("/3", (req, res) -> res.status(200).sendString(Mono.just("OK")))).bindNow();
AtomicInteger onRequestCount = new AtomicInteger();
AtomicInteger onResponseCount = new AtomicInteger();
AtomicInteger onRedirectCount = new AtomicInteger();
AtomicInteger doOnResponseError = new AtomicInteger();
Tuple2<String, HttpResponseStatus> response = createClient(disposableServer::address).followRedirect(true).doOnRequest((r, c) -> onRequestCount.incrementAndGet()).doOnResponse((r, c) -> onResponseCount.incrementAndGet()).doOnRedirect((r, c) -> onRedirectCount.incrementAndGet()).doOnResponseError((r, t) -> doOnResponseError.incrementAndGet()).get().uri("/1").responseSingle((res, bytes) -> bytes.asString().zipWith(Mono.just(res.status()))).block(Duration.ofSeconds(30));
assertThat(response).isNotNull();
assertThat(response.getT1()).isEqualTo("OK");
assertThat(response.getT2()).isEqualTo(HttpResponseStatus.OK);
assertThat(onRequestCount.get()).isEqualTo(2);
assertThat(onResponseCount.get()).isEqualTo(1);
assertThat(onRedirectCount.get()).isEqualTo(1);
assertThat(doOnResponseError.get()).isEqualTo(0);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project reactor-netty by reactor.
the class HttpClientOperationsTest method testStatus.
@Test
void testStatus() {
doTestStatus(HttpResponseStatus.OK);
doTestStatus(new HttpResponseStatus(200, "Some custom reason phrase for 200 status code"));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project apollo by apollo-rsps.
the class HttpRequestWorker method service.
@Override
protected void service(ResourceProvider provider, Channel channel, HttpRequest request) throws IOException {
String path = request.getUri();
Optional<ByteBuffer> buf = provider.get(path);
HttpResponseStatus status = HttpResponseStatus.OK;
String mime = getMimeType(request.getUri());
if (!buf.isPresent()) {
status = HttpResponseStatus.NOT_FOUND;
mime = "text/html";
}
ByteBuf wrapped = buf.isPresent() ? Unpooled.wrappedBuffer(buf.get()) : createErrorPage(status, "The page you requested could not be found.");
HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), status);
response.headers().set("Date", new Date());
response.headers().set("Server", SERVER_IDENTIFIER);
response.headers().set("Content-type", mime + ", charset=" + CHARACTER_SET.name());
response.headers().set("Cache-control", "no-cache");
response.headers().set("Pragma", "no-cache");
response.headers().set("Expires", new Date(0));
response.headers().set("Connection", "close");
response.headers().set("Content-length", wrapped.readableBytes());
channel.write(response);
channel.writeAndFlush(wrapped).addListener(ChannelFutureListener.CLOSE);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus in project turbo-rpc by hank-whu.
the class RestHttResponseEncoder method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!(msg instanceof RestHttpResponse)) {
ctx.write(msg, promise);
return;
}
RestHttpResponse restHttpResponse = (RestHttpResponse) msg;
HttpResponseStatus status = restHttpResponse.getStatus();
if (status == null) {
status = INTERNAL_SERVER_ERROR;
}
if (restHttpResponse.getResult() == null) {
status = INTERNAL_SERVER_ERROR;
restHttpResponse.setStatus(status);
restHttpResponse.setResult("UNKNOWN");
}
doResponse(ctx, promise, restHttpResponse);
}
Aggregations