Search in sources :

Example 16 with DecoderResult

use of io.netty.handler.codec.DecoderResult in project netty by netty.

the class HttpSnoopServerHandler method appendDecoderResult.

private static void appendDecoderResult(StringBuilder buf, HttpObject o) {
    DecoderResult result = o.decoderResult();
    if (result.isSuccess()) {
        return;
    }
    buf.append(".. WITH DECODER FAILURE: ");
    buf.append(result.cause());
    buf.append("\r\n");
}
Also used : DecoderResult(io.netty.handler.codec.DecoderResult)

Example 17 with DecoderResult

use of io.netty.handler.codec.DecoderResult in project netty by netty.

the class HttpInvalidMessageTest method testResponseWithBadInitialLine.

@Test
public void testResponseWithBadInitialLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8));
    HttpResponse res = ch.readInbound();
    DecoderResult dr = res.decoderResult();
    assertFalse(dr.isSuccess());
    assertTrue(dr.isFailure());
    ensureInboundTrafficDiscarded(ch);
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DecoderResult(io.netty.handler.codec.DecoderResult) Test(org.junit.Test)

Example 18 with DecoderResult

use of io.netty.handler.codec.DecoderResult in project netty by netty.

the class HttpInvalidMessageTest method testRequestWithBadHeader.

@Test
public void testRequestWithBadHeader() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
    ch.writeInbound(Unpooled.copiedBuffer("GET /maybe-something HTTP/1.0\r\n", CharsetUtil.UTF_8));
    ch.writeInbound(Unpooled.copiedBuffer("Good_Name: Good Value\r\n", CharsetUtil.UTF_8));
    ch.writeInbound(Unpooled.copiedBuffer("Bad=Name: Bad Value\r\n", CharsetUtil.UTF_8));
    ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8));
    HttpRequest req = ch.readInbound();
    DecoderResult dr = req.decoderResult();
    assertFalse(dr.isSuccess());
    assertTrue(dr.isFailure());
    assertEquals("Good Value", req.headers().get(of("Good_Name")));
    assertEquals("/maybe-something", req.uri());
    ensureInboundTrafficDiscarded(ch);
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DecoderResult(io.netty.handler.codec.DecoderResult) Test(org.junit.Test)

Aggregations

DecoderResult (io.netty.handler.codec.DecoderResult)18 Test (org.junit.Test)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 Buffer (io.vertx.core.buffer.Buffer)2 WebSocketFrameInternal (io.vertx.core.http.impl.ws.WebSocketFrameInternal)2 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 HttpObject (io.netty.handler.codec.http.HttpObject)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 HttpVersion (io.netty.handler.codec.http.HttpVersion)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1 WebSocketFrameImpl (io.vertx.core.http.impl.ws.WebSocketFrameImpl)1