use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project flink by apache.
the class HandlerRedirectUtils method getRedirectResponse.
public static HttpResponse getRedirectResponse(String redirectAddress, String path, boolean httpsEnabled) throws Exception {
checkNotNull(redirectAddress, "Redirect address");
checkNotNull(path, "Path");
String protocol = httpsEnabled ? "https" : "http";
String newLocation = String.format("%s://%s%s", protocol, redirectAddress, path);
HttpResponse redirectResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.TEMPORARY_REDIRECT);
redirectResponse.headers().set(HttpHeaders.Names.LOCATION, newLocation);
redirectResponse.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);
return redirectResponse;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project flink by apache.
the class StaticFileServerHandler method channelRead0.
// ------------------------------------------------------------------------
// Responses to requests
// ------------------------------------------------------------------------
@Override
public void channelRead0(ChannelHandlerContext ctx, Routed routed) throws Exception {
if (localJobManagerAddressFuture.isCompleted()) {
if (localJobManagerAddress == null) {
localJobManagerAddress = Await.result(localJobManagerAddressFuture, timeout);
}
final HttpRequest request = routed.request();
String requestPath = routed.path();
// make sure we request the "index.html" in case there is a directory request
if (requestPath.endsWith("/")) {
requestPath = requestPath + "index.html";
}
// in case the files being accessed are logs or stdout files, find appropriate paths.
if (requestPath.equals("/jobmanager/log") || requestPath.equals("/jobmanager/stdout")) {
requestPath = "";
}
Option<Tuple2<ActorGateway, Integer>> jobManager = retriever.getJobManagerGatewayAndWebPort();
if (jobManager.isDefined()) {
// Redirect to leader if necessary
String redirectAddress = HandlerRedirectUtils.getRedirectAddress(localJobManagerAddress, jobManager.get());
if (redirectAddress != null) {
HttpResponse redirect = HandlerRedirectUtils.getRedirectResponse(redirectAddress, requestPath, httpsEnabled);
KeepAliveWrite.flush(ctx, routed.request(), redirect);
} else {
respondAsLeader(ctx, request, requestPath);
}
} else {
KeepAliveWrite.flush(ctx, routed.request(), HandlerRedirectUtils.getUnavailableResponse());
}
} else {
KeepAliveWrite.flush(ctx, routed.request(), HandlerRedirectUtils.getUnavailableResponse());
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeHeaders.
@Test
public void testUpgradeHeaders() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
assertTrue(ch.writeOutbound(response));
Http2HeadersFrame headersFrame = ch.readOutbound();
assertThat(headersFrame.headers().status().toString(), is("200"));
assertFalse(headersFrame.isEndStream());
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.
the class WebSocketServerExtensionHandler method write.
@Override
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof HttpResponse && WebSocketExtensionUtil.isWebsocketUpgrade(((HttpResponse) msg).headers()) && validExtensions != null) {
HttpResponse response = (HttpResponse) msg;
String headerValue = response.headers().getAsString(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS);
for (WebSocketServerExtension extension : validExtensions) {
WebSocketExtensionData extensionData = extension.newReponseData();
headerValue = WebSocketExtensionUtil.appendExtension(headerValue, extensionData.name(), extensionData.parameters());
}
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
for (WebSocketServerExtension extension : validExtensions) {
WebSocketExtensionDecoder decoder = extension.newExtensionDecoder();
WebSocketExtensionEncoder encoder = extension.newExtensionEncoder();
ctx.pipeline().addAfter(ctx.name(), decoder.getClass().getName(), decoder);
ctx.pipeline().addAfter(ctx.name(), encoder.getClass().getName(), encoder);
}
}
ctx.pipeline().remove(ctx.name());
}
});
if (headerValue != null) {
response.headers().set(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS, headerValue);
}
}
super.write(ctx, msg, promise);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty-socketio by mrniko.
the class PollingTransport method sendError.
private void sendError(ChannelHandlerContext ctx) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
ctx.channel().writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
}
Aggregations