@Override
  public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e)
      throws Exception {

    if (!chunked) {
      final HttpRequest request = (HttpRequest) e.getMessage();

      final ChannelBuffer buffer = request.getContent();
      receivedData.write(buffer.array());
      // System.out.println("received "+buffer.array() );
      // System.out.println(buffer.array().length);
      if (!request.isChunked()) {
        processRequest(e);
      } else {
        chunked = true;
      }
      // final boolean keepAlive = isKeepAlive(request);
    } else {
      final HttpChunk chunk = (HttpChunk) e.getMessage();
      final ChannelBuffer buffer = chunk.getContent();
      receivedData.write(buffer.array());
      if (chunk.isLast()) {
        processRequest(e);
      }
    }
  }
Esempio n. 2
0
  private HttpRequest rewriteRequest(HttpRequest request, boolean isStreaming) {
    if (!isStreaming) {
      return request;
    }

    if (!request.isChunked() || request.getContent().readable()) {
      request.setChunked(true);
      request.setContent(ChannelBuffers.EMPTY_BUFFER);
    }
    return request;
  }
Esempio n. 3
0
  HttpMethodInfo(
      Method method,
      HttpHandler handler,
      HttpRequest request,
      HttpResponder responder,
      Object[] args) {
    this.method = method;
    this.handler = handler;
    this.isChunkedRequest = request.isChunked();
    this.requestContent = request.getContent();
    this.responder = responder;
    this.isStreaming = BodyConsumer.class.isAssignableFrom(method.getReturnType());

    // The actual arguments list to invoke handler method
    this.args = new Object[args.length + 2];
    this.args[0] = rewriteRequest(request, isStreaming);
    this.args[1] = responder;
    System.arraycopy(args, 0, this.args, 2, args.length);
  }