use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project reactor-netty by reactor.
the class WebsocketClientOperations method onInboundNext.
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void onInboundNext(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof FullHttpResponse) {
started = true;
channel().pipeline().remove(HttpObjectAggregator.class);
FullHttpResponse response = (FullHttpResponse) msg;
setNettyResponse(response);
if (notRedirected(response)) {
try {
handshaker.finishHandshake(channel(), response);
// This change is needed after the Netty change https://github.com/netty/netty/pull/11966
ctx.read();
listener().onStateChange(this, HttpClientState.RESPONSE_RECEIVED);
} catch (Exception e) {
onInboundError(e);
// "FutureReturnValueIgnored" this is deliberate
ctx.close();
} finally {
// Release unused content (101 status)
response.content().release();
}
} else {
response.content().release();
listener().onUncaughtException(this, redirecting);
}
return;
}
if (!this.proxyPing && msg instanceof PingWebSocketFrame) {
// "FutureReturnValueIgnored" this is deliberate
ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) msg).content()));
ctx.read();
return;
}
if (msg instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) msg).isFinalFragment()) {
if (log.isDebugEnabled()) {
log.debug(format(channel(), "CloseWebSocketFrame detected. Closing Websocket"));
}
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(true, ((CloseWebSocketFrame) msg).rsv(), ((CloseWebSocketFrame) msg).content());
if (closeFrame.statusCode() != -1) {
sendCloseNow(closeFrame);
} else {
sendCloseNow(closeFrame, WebSocketCloseStatus.EMPTY);
}
onInboundComplete();
} else if (msg != LastHttpContent.EMPTY_LAST_CONTENT) {
super.onInboundNext(ctx, msg);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project proxyee-down by monkeyWie.
the class EmbedHttpServer method invoke.
// 根据请求uri找到对应的处理类方法执行
public FullHttpResponse invoke(String uri, Channel channel, FullHttpRequest request) throws Exception {
if (controllerList != null) {
for (Object obj : controllerList) {
Class<?> clazz = obj.getClass();
RequestMapping mapping = clazz.getAnnotation(RequestMapping.class);
if (mapping != null) {
String mappingUri = fixUri(mapping.value()[0]);
for (Method actionMethod : clazz.getMethods()) {
RequestMapping subMapping = actionMethod.getAnnotation(RequestMapping.class);
if (subMapping != null) {
String subMappingUri = fixUri(subMapping.value()[0]);
if (uri.equalsIgnoreCase(mappingUri + subMappingUri)) {
return (FullHttpResponse) actionMethod.invoke(obj, channel, request);
}
}
}
}
}
}
return defaultController.handle(channel, request);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project proxyee-down by monkeyWie.
the class PacController method build.
@RequestMapping("pdown.pac")
public FullHttpResponse build(Channel channel, FullHttpRequest request) throws Exception {
Set<String> domains = ExtensionContent.getProxyWildCards();
String pacContent = PAC_TEMPLATE.replace("{port}", DownApplication.INSTANCE.PROXY_PORT + "");
if (domains != null && domains.size() > 0) {
StringBuilder domainsBuilder = new StringBuilder();
for (String domain : domains) {
if (domainsBuilder.length() != 0) {
domainsBuilder.append(",");
}
domainsBuilder.append("'" + domain + "'");
}
pacContent = pacContent.replace("{domains}", domainsBuilder.toString());
} else {
pacContent = pacContent.replace("{domains}", "");
}
FullHttpResponse httpResponse = HttpHandlerUtil.buildContent(pacContent, "application/x-ns-proxy-autoconfig");
httpResponse.headers().set(HttpHeaderNames.CACHE_CONTROL, HttpHeaderValues.NO_CACHE);
httpResponse.headers().set(HttpHeaderNames.PRAGMA, HttpHeaderValues.NO_CACHE);
httpResponse.headers().set(HttpHeaderNames.EXPIRES, 0);
return httpResponse;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project proxyee-down by monkeyWie.
the class HttpHandlerUtil method buildJson.
public static FullHttpResponse buildJson(Object obj, Include include) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, AsciiString.cached("application/json; charset=utf-8"));
if (obj != null) {
try {
ObjectMapper objectMapper = new ObjectMapper();
if (include != null) {
objectMapper.setSerializationInclusion(include);
}
String content = objectMapper.writeValueAsString(obj);
response.content().writeBytes(content.getBytes(Charset.forName("utf-8")));
} catch (JsonProcessingException e) {
response.setStatus(HttpResponseStatus.SERVICE_UNAVAILABLE);
}
}
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
return response;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project ballerina by ballerina-lang.
the class WebSocketClientHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
logger.info("WebSocket Client connected!");
handshakeFuture.setSuccess();
isOpen = true;
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
textReceived = textFrame.text();
} else if (frame instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame;
bufferReceived = binaryFrame.content().nioBuffer();
} else if (frame instanceof PingWebSocketFrame) {
PingWebSocketFrame pingFrame = (PingWebSocketFrame) frame;
isPing = true;
bufferReceived = pingFrame.content().nioBuffer();
} else if (frame instanceof PongWebSocketFrame) {
PongWebSocketFrame pongFrame = (PongWebSocketFrame) frame;
isPong = true;
bufferReceived = pongFrame.content().nioBuffer();
} else if (frame instanceof CloseWebSocketFrame) {
ch.close().sync();
isOpen = false;
}
}
Aggregations