comparison src/org/eclipse/jetty/http/HttpParser.java @ 1041:35e3c864d7a7

make View package local
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 00:47:23 -0600
parents b71ad168fe34
children dd71a59fcf72
comparison
equal deleted inserted replaced
1040:3e4949834f3e 1041:35e3c864d7a7
19 package org.eclipse.jetty.http; 19 package org.eclipse.jetty.http;
20 20
21 import java.io.IOException; 21 import java.io.IOException;
22 22
23 import org.eclipse.jetty.io.Buffer; 23 import org.eclipse.jetty.io.Buffer;
24 import org.eclipse.jetty.io.ByteArrayBuffer;
24 import org.eclipse.jetty.io.BufferUtil; 25 import org.eclipse.jetty.io.BufferUtil;
25 import org.eclipse.jetty.io.EndPoint; 26 import org.eclipse.jetty.io.EndPoint;
26 import org.eclipse.jetty.io.EofException; 27 import org.eclipse.jetty.io.EofException;
27 import org.eclipse.jetty.io.View;
28 import org.eclipse.jetty.util.StringUtil; 28 import org.eclipse.jetty.util.StringUtil;
29 import org.slf4j.Logger; 29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory; 30 import org.slf4j.LoggerFactory;
31 31
32 public final class HttpParser 32 public final class HttpParser
65 private String _tok1 = ""; // Saved token: header value, request URI or response code 65 private String _tok1 = ""; // Saved token: header value, request URI or response code
66 private String _multiLineValue; 66 private String _multiLineValue;
67 private int _responseStatus; // If >0 then we are parsing a response 67 private int _responseStatus; // If >0 then we are parsing a response
68 private boolean _persistent; 68 private boolean _persistent;
69 69
70 private final View _contentView = new View(); // View of the content in the buffer for {@link Input} 70 private Buffer _contentView = new ByteArrayBuffer(0); // View of the content in the buffer for {@link Input}
71 private int _state = STATE_START; 71 private int _state = STATE_START;
72 private byte _eol; 72 private byte _eol;
73 private int _length; 73 private int _length;
74 private long _contentLength; 74 private long _contentLength;
75 private long _contentPosition; 75 private long _contentPosition;
206 { 206 {
207 if (_buffer.remaining()>0 && !_headResponse) 207 if (_buffer.remaining()>0 && !_headResponse)
208 { 208 {
209 Buffer chunk = _buffer.get(_buffer.remaining()); 209 Buffer chunk = _buffer.get(_buffer.remaining());
210 _contentPosition += chunk.remaining(); 210 _contentPosition += chunk.remaining();
211 _contentView.update(chunk); 211 _contentView = chunk;
212 _handler.content(); // May recurse here 212 _handler.content(); // May recurse here
213 } 213 }
214 } 214 }
215 215
216 // was this unexpected? 216 // was this unexpected?
731 731
732 // ========================== 732 // ==========================
733 733
734 // Handle _content 734 // Handle _content
735 length=_buffer.remaining(); 735 length=_buffer.remaining();
736 Buffer chunk;
737 last=_state; 736 last=_state;
738 while (_state > STATE_END && length > 0) 737 while (_state > STATE_END && length > 0)
739 { 738 {
740 if (last!=_state) 739 if (last!=_state)
741 { 740 {
751 } 750 }
752 _eol=0; 751 _eol=0;
753 switch (_state) 752 switch (_state)
754 { 753 {
755 case STATE_EOF_CONTENT: 754 case STATE_EOF_CONTENT:
756 chunk=_buffer.get(_buffer.remaining()); 755 {
756 Buffer chunk = _buffer.get(_buffer.remaining());
757 _contentPosition += chunk.remaining(); 757 _contentPosition += chunk.remaining();
758 _contentView.update(chunk); 758 _contentView = chunk;
759 _handler.content(); // May recurse here 759 _handler.content(); // May recurse here
760 // TODO adjust the _buffer to keep unconsumed content 760 // TODO adjust the _buffer to keep unconsumed content
761 return 1; 761 return 1;
762 }
762 763
763 case STATE_CONTENT: 764 case STATE_CONTENT:
764 { 765 {
765 long remaining=_contentLength - _contentPosition; 766 long remaining=_contentLength - _contentPosition;
766 if (remaining == 0) 767 if (remaining == 0)
775 // We can cast reamining to an int as we know that it is smaller than 776 // We can cast reamining to an int as we know that it is smaller than
776 // or equal to length which is already an int. 777 // or equal to length which is already an int.
777 length=(int)remaining; 778 length=(int)remaining;
778 } 779 }
779 780
780 chunk=_buffer.get(length); 781 Buffer chunk = _buffer.get(length);
781 _contentPosition += chunk.remaining(); 782 _contentPosition += chunk.remaining();
782 _contentView.update(chunk); 783 _contentView = chunk;
783 _handler.content(); // May recurse here 784 _handler.content(); // May recurse here
784 785
785 if(_contentPosition == _contentLength) 786 if(_contentPosition == _contentLength)
786 { 787 {
787 _state = _persistent?STATE_END:STATE_SEEKING_EOF; 788 _state = _persistent?STATE_END:STATE_SEEKING_EOF;
866 _state=STATE_CHUNKED_CONTENT; 867 _state=STATE_CHUNKED_CONTENT;
867 break; 868 break;
868 } 869 }
869 else if (length > remaining) 870 else if (length > remaining)
870 length=remaining; 871 length=remaining;
871 chunk=_buffer.get(length); 872 Buffer chunk = _buffer.get(length);
872 _contentPosition += chunk.remaining(); 873 _contentPosition += chunk.remaining();
873 _chunkPosition += chunk.remaining(); 874 _chunkPosition += chunk.remaining();
874 _contentView.update(chunk); 875 _contentView = chunk;
875 _handler.content(); // May recurse here 876 _handler.content(); // May recurse here
876 // TODO adjust the _buffer to keep unconsumed content 877 // TODO adjust the _buffer to keep unconsumed content
877 return 1; 878 return 1;
878 } 879 }
879 880
1020 /* (non-Javadoc) 1021 /* (non-Javadoc)
1021 * @see java.io.InputStream#available() 1022 * @see java.io.InputStream#available()
1022 */ 1023 */
1023 public int available() throws IOException 1024 public int available() throws IOException
1024 { 1025 {
1025 if (_contentView!=null && _contentView.remaining()>0) 1026 if (_contentView.remaining()>0)
1026 return _contentView.remaining(); 1027 return _contentView.remaining();
1027 1028
1028 if (_endp.isBlocking()) 1029 if (_endp.isBlocking())
1029 { 1030 {
1030 return 0; 1031 return 0;
1031 } 1032 }
1032 1033
1033 parseNext(); 1034 parseNext();
1034 return _contentView==null?0:_contentView.remaining(); 1035 return _contentView.remaining();
1035 } 1036 }
1036 1037
1037 1038
1038 public interface EventHandler 1039 public interface EventHandler
1039 { 1040 {