use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultHttpResponse in project tesla by linking12.
the class ProxyUtils method duplicateHttpResponse.
public static HttpResponse duplicateHttpResponse(HttpResponse originalResponse) {
DefaultHttpResponse newResponse = new DefaultHttpResponse(originalResponse.protocolVersion(), originalResponse.status());
newResponse.headers().add(originalResponse.headers());
return newResponse;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultHttpResponse in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullresp_firstcontentdisposed.
@Test
public final void test_httpobjs2fullresp_firstcontentdisposed() throws Exception {
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
final HttpContent[] resp_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> resps = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(response);
this.addAll(Arrays.asList(resp_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
// release [0]'s content
resp_contents[0].release();
FullHttpResponse fullresp = null;
thrown.expect(IllegalReferenceCountException.class);
try {
fullresp = Nettys.httpobjs2fullresp(resps);
} finally {
assertNull(fullresp);
RxActions.applyArrayBy(Arrays.copyOfRange(resp_contents, 1, resp_contents.length), new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultHttpResponse in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullresp_misslastcontent.
@Test
public final void test_httpobjs2fullresp_misslastcontent() throws Exception {
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
final HttpContent[] resp_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> resps = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(response);
this.addAll(Arrays.asList(resp_contents));
}
};
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
FullHttpResponse fullresp = null;
thrown.expect(RuntimeException.class);
try {
fullresp = Nettys.httpobjs2fullresp(resps);
} finally {
assertNull(fullresp);
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultHttpResponse in project reactor-netty by reactor.
the class HttpOperationsTest method httpAndJsonDecoders.
@Test
public void httpAndJsonDecoders() {
EmbeddedChannel channel = new EmbeddedChannel();
NettyContext testContext = () -> channel;
ChannelHandler handler = new JsonObjectDecoder(true);
testContext.addHandlerLast("foo", handler);
HttpOperations.autoAddHttpExtractor(testContext, "foo", handler);
String json1 = "[{\"some\": 1} , {\"valu";
String json2 = "e\": true, \"test\": 1}]";
Object[] content = new Object[3];
content[0] = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
content[1] = new DefaultHttpContent(Unpooled.copiedBuffer(json1, CharsetUtil.UTF_8));
content[2] = new DefaultLastHttpContent(Unpooled.copiedBuffer(json2, CharsetUtil.UTF_8));
channel.writeInbound(content);
Object t = channel.readInbound();
assertThat(t, instanceOf(HttpResponse.class));
assertThat(t, not(instanceOf(HttpContent.class)));
t = channel.readInbound();
assertThat(t, instanceOf(ByteBuf.class));
assertThat(((ByteBuf) t).toString(CharsetUtil.UTF_8), is("{\"some\": 1}"));
((ByteBuf) t).release();
t = channel.readInbound();
assertThat(t, instanceOf(ByteBuf.class));
assertThat(((ByteBuf) t).toString(CharsetUtil.UTF_8), is("{\"value\": true, \"test\": 1}"));
((ByteBuf) t).release();
t = channel.readInbound();
assertThat(t, is(LastHttpContent.EMPTY_LAST_CONTENT));
((LastHttpContent) t).release();
t = channel.readInbound();
assertThat(t, nullValue());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultHttpResponse in project moco by dreamhead.
the class ActualWebSocketServer method connectRequest.
public void connectRequest(final ChannelHandlerContext ctx, final FullHttpRequest request) {
QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
final String actual = decoder.path();
if (!uri.equals(actual)) {
ctx.writeAndFlush(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
return;
}
WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(this.uri, null, false);
WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(request);
Channel channel = ctx.channel();
if (handshaker == null) {
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(channel);
return;
}
handshaker.handshake(channel, request);
connect(channel);
sendConnected(channel);
}
Aggregations