Package io.netty.handler.codec.http

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


    }

    @Override
    public void setData(ByteBuffer buf)
    {
        chunk = new DefaultHttpContent(NettyServer.copyBuffer(buf));
    }
View Full Code Here


        ByteBuf newBuf = safeBuffer(content, allocator);
        if (msg instanceof LastHttpContent) {
          LastHttpContent last = (LastHttpContent) msg;
          return new AssembledLastHttpContent(newBuf, last.trailingHeaders(), last.getDecoderResult());
        } else {
          return new DefaultHttpContent(newBuf);
        }
      }
    } else if (msg instanceof WebSocketFrame) {
      ByteBuf payload = safeBuffer((WebSocketFrame) msg, allocator);
      boolean isFinal = ((WebSocketFrame) msg).isFinalFragment();
View Full Code Here

    if (!headWritten) {
      prepareHeaders();
      channelFuture = conn.writeToChannel(new AssembledHttpResponse(response, chunk));
      headWritten = true;
    else {
      channelFuture = conn.writeToChannel(new DefaultHttpContent(chunk));
    }

    conn.addFuture(completionHandler, channelFuture);
    return this;
  }
View Full Code Here

  @Override
  public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof ByteBuf) {
      // convert ByteBuf to HttpContent to make it work with compression. This is needed as we use the
      // ChunkedWriteHandler to send files when compression is enabled.
      msg =  new DefaultHttpContent((ByteBuf) msg);
    }
    super.write(ctx, msg, promise);
  }
View Full Code Here

  }

  synchronized void handleData(Buffer data) {
    if (decoder != null) {
      try {
        decoder.offer(new DefaultHttpContent(data.getByteBuf().duplicate()));
      } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
        handleException(e);
      }
    }
    if (dataHandler != null) {
View Full Code Here

    this.response = response;
    this.content = content;
  }

  AssembledHttpResponse(HttpResponse response, ByteBuf buf) {
    this(response, new DefaultHttpContent(buf));
  }
View Full Code Here

            conn.writeToChannel(new DefaultLastHttpContent(buff, false));
          } else {
            conn.writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT);
          }
        } else {
          conn.writeToChannel(new DefaultHttpContent(buff));
        }
      }
      if (end) {
        if (conn.metrics().isEnabled()) conn.metrics().bytesWritten(conn.remoteAddress(), written);
View Full Code Here

class AssembledHttpRequest implements HttpContent, HttpRequest {
  private final HttpRequest request;
  protected final HttpContent content;

  AssembledHttpRequest(HttpRequest request, ByteBuf buf) {
    this(request, new DefaultHttpContent(buf));
  }
View Full Code Here

      if (!started) {
        startResponse();
      }

      final HttpContent chunk = new DefaultHttpContent(content);

      // FIXME Why is this closing the connection in netty 4.0.0.Beta3?
      context.write(chunk);

    }
View Full Code Here

        assertThat(response.getStatus(), equalTo(HttpResponseStatus.OK));
        assertThat(response.headers().get(CONTENT_TYPE), equalTo(Transports.CONTENT_TYPE_JAVASCRIPT));
        SockJsTestUtil.assertCORSHeaders(response, "*");
        SockJsTestUtil.verifyNoCacheHeaders(response);

        final DefaultHttpContent prelude = ch.readOutbound();
        assertThat(prelude.content().readableBytes(), is(PreludeFrame.CONTENT_SIZE + 1));
        final ByteBuf buffer = Unpooled.buffer(PreludeFrame.CONTENT_SIZE + 1);
        prelude.content().readBytes(buffer);
        buffer.release();

        final DefaultHttpContent openResponse = ch.readOutbound();
        assertThat(openResponse.content().toString(UTF_8), equalTo("o\n"));

        final FullHttpResponse validSend = xhrSendRequest(sessionUrl, "[\"x\"]", serviceFactory);
        assertThat(validSend.getStatus(), is(HttpResponseStatus.NO_CONTENT));

        final DefaultHttpContent chunk = ch.readOutbound();
        assertThat(chunk.content().toString(UTF_8), equalTo("a[\"x\"]\n"));
    }
View Full Code Here

TOP

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

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.