Package org.jboss.netty.handler.codec.http

Examples of org.jboss.netty.handler.codec.http.HttpMessage


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

      Object msg = e.getMessage();
      HttpMessage currentMessage = this.currentMessage;

      if (msg instanceof HttpMessage) {
          HttpMessage m = (HttpMessage) msg;
          if (m.isChunked()) {
              // A chunked message - remove 'Transfer-Encoding' header,
              // initialize the cumulative buffer, and wait for incoming chunks.
              List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
              encodings.remove(HttpHeaders.Values.CHUNKED);
              if (encodings.isEmpty()) {
                  m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
              }
              m.setContent(ChannelBuffers.dynamicBuffer(e.getChannel().getConfig().getBufferFactory()));
              this.currentMessage = m;
          } else {
              // Not a chunked message - pass through.
              this.currentMessage = null;
              ctx.sendUpstream(e);
View Full Code Here


        if (!(msg instanceof HttpMessage)) {
            ctx.sendUpstream(e);
            return;
        }

        HttpMessage m = (HttpMessage) msg;
        String acceptedEncoding = m.getHeader(HttpHeaders.Names.ACCEPT_ENCODING);
        if (acceptedEncoding == null) {
            acceptedEncoding = HttpHeaders.Values.IDENTITY;
        }
        boolean offered = acceptEncodingQueue.offer(acceptedEncoding);
        assert offered;
View Full Code Here

        Object msg = e.getMessage();
        if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
            // 100-continue response must be passed through.
            ctx.sendDownstream(e);
        } else  if (msg instanceof HttpMessage) {
            HttpMessage m = (HttpMessage) msg;

            encoder = null;

            // Determine the content encoding.
            String acceptEncoding = acceptEncodingQueue.poll();
            if (acceptEncoding == null) {
               acceptEncoding = this.previousEncoding;
            } else {
              this.previousEncoding = acceptEncoding;
            }

            if ((encoder = newContentEncoder(acceptEncoding)) != null) {
                // Encode the content and remove or replace the existing headers
                // so that the message looks like a decoded message.
                m.setHeader(
                        HttpHeaders.Names.CONTENT_ENCODING,
                        getTargetContentEncoding(acceptEncoding));

                if (!m.isChunked()) {
                    ChannelBuffer content = m.getContent();
                    // Encode the content.
                    content = ChannelBuffers.wrappedBuffer(
                            encode(content), finishEncode());

                    // Replace the content.
                    m.setContent(content);

                   
//                    if (m.containsHeader(HttpHeaders.Names.CONTENT_LENGTH)) {
//                        m.setHeader(
//                                HttpHeaders.Names.CONTENT_LENGTH,
//                                Integer.toString(content.readableBytes()));
//                    }
                }
            }
            //ALWAYS SET THE Content_LEngth
            m.setHeader(
                    HttpHeaders.Names.CONTENT_LENGTH,
                    Integer.toString(m.getContent().readableBytes()));
            // Because HttpMessage is a mutable object, we can simply forward the write request.
            ctx.sendDownstream(e);
        } else if (msg instanceof HttpChunk) {
            HttpChunk c = (HttpChunk) msg;
            ChannelBuffer content = c.getContent();
View Full Code Here

     Object msg = e.getMessage();
     if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
       // 100-continue response must be passed through.
       ctx.sendDownstream(e);
     } else  if (msg instanceof HttpMessage) {
       HttpMessage m = (HttpMessage) msg;
       //make sure content length is set.
       if (!m.containsHeader(HttpHeaders.Names.CONTENT_LENGTH)) {
         if (m.getContent() != null && m.getContent().readableBytes() > 0) {
           m.setHeader(HttpHeaders.Names.CONTENT_LENGTH, m.getContent().readableBytes());
         } else {
           m.setHeader(HttpHeaders.Names.CONTENT_LENGTH, 0);
         }
       }
     }
     ctx.sendDownstream(e);
   }
View Full Code Here

        }
        return false;
    }

    private Object reset() {
        HttpMessage message = this.message;
        ChannelBuffer content = this.content;

        if (content != null) {
            message.setContent(content);
            this.content = null;
        }
        this.message = null;

        checkpoint(State.SKIP_CONTROL_CHARS);
View Full Code Here

        }
    }

    private State readHeaders(ChannelBuffer buffer) throws TooLongFrameException {
        headerSize = 0;
        final HttpMessage message = this.message;
        String line = readHeader(buffer);
        String lastHeader = null;
        if (line.length() != 0) {
            message.clearHeaders();
            do {
                char firstChar = line.charAt(0);
                if (lastHeader != null && (firstChar == ' ' || firstChar == '\t')) {
                    List<String> current = message.getHeaders(lastHeader);
                    int lastPos = current.size() - 1;
                    String newString = current.get(lastPos) + line.trim();
                    current.set(lastPos, newString);
                } else {
                    String[] header = splitHeader(line);
                    message.addHeader(header[0], header[1]);
                    lastHeader = header[0];
                }

                line = readHeader(buffer);
            } while (line.length() != 0);
        }

        State nextState;

        if (isContentAlwaysEmpty(message)) {
            nextState = State.SKIP_CONTROL_CHARS;
        } else if (message.isChunked()) {
            // HttpMessage.isChunked() returns true when either:
            // 1) HttpMessage.setChunked(true) was called or
            // 2) 'Transfer-Encoding' is 'chunked'.
            // Because this decoder did not call HttpMessage.setChunked(true)
            // yet, HttpMessage.isChunked() should return true only when
View Full Code Here

        } else if (msg instanceof SpdyHeadersFrame) {

            SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
            int streamId = spdyHeadersFrame.getStreamId();
            HttpMessage httpMessage = getMessage(streamId);

            // If message is not in map discard HEADERS frame.
            if (httpMessage == null) {
                return null;
            }

            // Ignore trailers in a truncated HEADERS frame.
            if (!spdyHeadersFrame.isTruncated()) {
                for (Map.Entry<String, String> e : spdyHeadersFrame.getHeaders()) {
                    httpMessage.addHeader(e.getKey(), e.getValue());
                }
            }

            if (spdyHeadersFrame.isLast()) {
                HttpHeaders.setContentLength(httpMessage, httpMessage.getContent().readableBytes());
                removeMessage(streamId);
                return httpMessage;
            }

        } else if (msg instanceof SpdyDataFrame) {

            SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
            int streamId = spdyDataFrame.getStreamId();
            HttpMessage httpMessage = getMessage(streamId);

            // If message is not in map discard Data Frame.
            if (httpMessage == null) {
                return null;
            }

            ChannelBuffer content = httpMessage.getContent();
            if (content.readableBytes() > maxContentLength - spdyDataFrame.getData().readableBytes()) {
                removeMessage(streamId);
                throw new TooLongFrameException(
                        "HTTP content length exceeded " + maxContentLength + " bytes.");
            }

            if (content == ChannelBuffers.EMPTY_BUFFER) {
                content = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory());
                content.writeBytes(spdyDataFrame.getData());
                httpMessage.setContent(content);
            } else {
                content.writeBytes(spdyDataFrame.getData());
            }

            if (spdyDataFrame.isLast()) {
View Full Code Here

        if (!(msg instanceof HttpMessage) && !(msg instanceof HttpChunk)) {
            ctx.sendUpstream(e);
            return;
        }

        HttpMessage currentMessage = this.currentMessage;
        File localFile = this.file;
        if (currentMessage == null) {
            HttpMessage m = (HttpMessage) msg;
            if (m.isChunked()) {
                final String localName = UUID.randomUUID().toString();
                // A chunked message - remove 'Transfer-Encoding' header,
                // initialize the cumulative buffer, and wait for incoming chunks.
                List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
                encodings.remove(HttpHeaders.Values.CHUNKED);
                if (encodings.isEmpty()) {
                    m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
                }
                this.currentMessage = m;
                this.file = new File(Play.tmpDir, localName);
                this.out = new FileOutputStream(file, true);
            } else {
View Full Code Here

        if (!(msg instanceof HttpMessage) && !(msg instanceof HttpChunk)) {
            ctx.sendUpstream(e);
            return;
        }

        HttpMessage currentMessage = this.currentMessage;
        File localFile = this.file;
        if (currentMessage == null) {
            HttpMessage m = (HttpMessage) msg;
            if (m.isChunked()) {
                final String localName = UUID.randomUUID().toString();
                // A chunked message - remove 'Transfer-Encoding' header,
                // initialize the cumulative buffer, and wait for incoming chunks.
                List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
                encodings.remove(HttpHeaders.Values.CHUNKED);
                if (encodings.isEmpty()) {
                    m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
                }
                this.currentMessage = m;
                this.file = new File(Play.tmpDir, localName);
                this.out = new FileOutputStream(file, true);
            } else {
View Full Code Here

        if (!(msg instanceof HttpMessage) && !(msg instanceof HttpChunk)) {
            ctx.sendUpstream(e);
            return;
        }

        HttpMessage currentMessage = this.currentMessage;
        File localFile = this.file;
        if (currentMessage == null) {
            HttpMessage m = (HttpMessage) msg;
            if (m.isChunked()) {
                final String localName = UUID.randomUUID().toString();
                // A chunked message - remove 'Transfer-Encoding' header,
                // initialize the cumulative buffer, and wait for incoming chunks.
                List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
                encodings.remove(HttpHeaders.Values.CHUNKED);
                if (encodings.isEmpty()) {
                    m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
                }
                this.currentMessage = m;
                this.file = new File(Yalp.tmpDir, localName);
                this.out = new FileOutputStream(file, true);
            } else {
View Full Code Here

TOP

Related Classes of org.jboss.netty.handler.codec.http.HttpMessage

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.