Package io.netty.handler.codec.http

Examples of io.netty.handler.codec.http.HttpContent


      DefaultHttpServerResponse resp = new DefaultHttpServerResponse(vertx, this, request);
      DefaultHttpServerRequest req = new DefaultHttpServerRequest(this, request, resp);
      handleRequest(req, resp);
    }
    if (msg instanceof HttpContent) {
        HttpContent chunk = (HttpContent) msg;
      if (chunk.content().isReadable()) {
        Buffer buff = new Buffer(chunk.content());
        handleChunk(buff);
      }

      //TODO chunk trailers
      if (msg instanceof LastHttpContent) {
View Full Code Here


      if (!started) {
        startResponse();
      }

      final HttpContent chunk = new DefaultHttpContent(content);
      context.write(chunk);

    }
View Full Code Here

                    }
                }
            }
            info.handle.event(new State.HeadersReceived(state.resp));
        } else if (msg instanceof HttpContent) {
            HttpContent c = (HttpContent) msg;
            info.handle.event(new State.ContentReceived(c));
            c.content().resetReaderIndex();
            if (c.content().readableBytes() > 0) {
                state.content.writeBytes(c.content());
            }
            state.content.resetReaderIndex();
            boolean last = c instanceof LastHttpContent;
            if (!last && state.resp.headers().get(HttpHeaders.Names.CONTENT_LENGTH) != null) {
                long len = Headers.CONTENT_LENGTH.toValue(state.resp.headers().get(HttpHeaders.Names.CONTENT_LENGTH));
                last = state.content.readableBytes() >= len;
            }
            if (last) {
                c.content().resetReaderIndex();
                sendFullResponse(ctx);
            }
        }
//        if (!info.listenerAdded) {
//            info.listenerAdded = true;
View Full Code Here

            @Override
            public void receive(State<?> state) {
                System.out.println("STATE " + state);
                seen.add(state.stateType());
                if (state.get() instanceof HttpContent) {
                    HttpContent content = (HttpContent) state.get();
                    ByteBuf bb = content.copy().content();
                    System.out.println("CHUNK " + bb.readableBytes() + " bytes");
                } else if (state.get() instanceof HttpResponse) {
//                    System.out.println("HEADERS: " + ((HttpResponse) state.get()).headers());
//                    for (Map.Entry<String,String> e : ((HttpResponse) state.get()).headers().entries()) {
//                        System.out.println(e.getKey() + ": " + e.getValue());
View Full Code Here

                throw new IllegalStateException( "Expected HTTP response 200 OK, got " + response.getStatus() );
            }
        }
        if ( msg instanceof HttpContent )
        {
            HttpContent content = (HttpContent) msg;
            buffer.append( content.content().toString( Charset.forName( "UTF-8" ) ) );

            if ( msg instanceof LastHttpContent )
            {
                done( ctx );
            }
View Full Code Here

        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(defaultHttpRequest);

        int firstChunk = 10;
        int middleChunk = 1024;

        HttpContent part1 = new DefaultHttpContent(Unpooled.wrappedBuffer(
                payload.substring(0, firstChunk).getBytes()));
        HttpContent part2 = new DefaultHttpContent(Unpooled.wrappedBuffer(
                payload.substring(firstChunk, firstChunk + middleChunk).getBytes()));
        HttpContent part3 = new DefaultHttpContent(Unpooled.wrappedBuffer(
                payload.substring(firstChunk + middleChunk, firstChunk + middleChunk * 2).getBytes()));
        HttpContent part4 = new DefaultHttpContent(Unpooled.wrappedBuffer(
                payload.substring(firstChunk + middleChunk * 2).getBytes()));

        decoder.offer(part1);
        decoder.offer(part2);
        decoder.offer(part3);
View Full Code Here

            } else {
                System.err.println("CONTENT {");
            }
        }
        if (msg instanceof HttpContent) {
            HttpContent chunk = (HttpContent) msg;
            System.err.println(chunk.content().toString(CharsetUtil.UTF_8));

            if (chunk instanceof LastHttpContent) {
                if (readingChunks) {
                    System.err.println("} END OF CHUNKED CONTENT");
                } else {
                    System.err.println("} END OF CONTENT");
                }
                readingChunks = false;
            } else {
                System.err.println(chunk.content().toString(CharsetUtil.UTF_8));
            }
        }
    }
View Full Code Here

        // check if the decoder was constructed before
        // if not it handles the form get
        if (decoder != null) {
            if (msg instanceof HttpContent) {
                // New chunk is received
                HttpContent chunk = (HttpContent) msg;
                try {
                    decoder.offer(chunk);
                } catch (ErrorDataDecoderException e1) {
                    e1.printStackTrace();
                    responseContent.append(e1.getMessage());
View Full Code Here

            valid = true;
        }
        if (msg instanceof HttpContent && !last) {

            HttpContent chunk = (HttpContent) msg;

            chunk.content().retain();
            SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(currentStreamId, chunk.content());
            spdyDataFrame.setLast(chunk instanceof LastHttpContent);
            if (chunk instanceof LastHttpContent) {
                LastHttpContent trailer = (LastHttpContent) chunk;
                HttpHeaders trailers = trailer.trailingHeaders();
                if (trailers.isEmpty()) {
View Full Code Here

            } else {
                System.err.println("CONTENT {");
            }
        }
        if (msg instanceof HttpContent) {
            HttpContent content = (HttpContent) msg;

            System.err.print(content.content().toString(CharsetUtil.UTF_8));
            System.err.flush();

            if (content instanceof LastHttpContent) {
                System.err.println("} END OF CONTENT");
                ctx.close();
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.http.HttpContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.