diff src/org/eclipse/jetty/http/HttpParser.java @ 1019:f126d30e04a4

start replacing BufferCache with StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 03:33:42 -0600
parents d2c3ff33387c
children 6be43ef1eb96
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpParser.java	Mon Oct 24 05:37:24 2016 -0600
+++ b/src/org/eclipse/jetty/http/HttpParser.java	Mon Oct 31 03:33:42 2016 -0600
@@ -67,7 +67,7 @@
 	private Buffer _body; // Buffer for large content
 	private Buffer _buffer; // The current buffer in use (either _header or _content)
 	private CachedBuffer _cached;
-	private final View.CaseInsensitive _tok0 = new View.CaseInsensitive(); // Saved token: header name, request method or response version
+	private String _tok0; // Saved token: header name, request method or response version
 	private final View.CaseInsensitive _tok1 = new View.CaseInsensitive(); // Saved token: header value, request URI or response code
 	private String _multiLineValue;
 	private int _responseStatus; // If >0 then we are parsing a response
@@ -172,7 +172,7 @@
 				return 0;
 
 			if (_buffer==null)
-				_buffer=getHeaderBuffer();
+				_buffer = getHeaderBuffer();
 
 
 			if (_state == STATE_CONTENT && _contentPosition == _contentLength)
@@ -290,8 +290,11 @@
 					case STATE_FIELD0:
 						if (ch == HttpTokens.SPACE)
 						{
-							_tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1);
-							_responseStatus = HttpVersions.CACHE.get(_tok0)==null?-1:0;
+//System.out.println("qqqqqqqqqqqqqqqq a "+_tok0);
+//							_tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1);
+							_tok0 = _buffer.peek(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()).toString();
+//System.out.println("qqqqqqqqqqqqqqqq b "+_tok0);
+							_responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0;
 							_state=STATE_SPACE1;
 							continue;
 						}
@@ -335,7 +338,8 @@
 						{
 							_eol=ch;
 							_state=STATE_HEADER;
-							_tok0.setPutIndex(_tok0.getIndex());
+//							_tok0.setPutIndex(_tok0.getIndex());
+							_tok0 = "";
 							_tok1.setPutIndex(_tok1.getIndex());
 							_multiLineValue=null;
 							continue;
@@ -355,7 +359,7 @@
 						else if (ch < HttpTokens.SPACE && ch>=0)
 						{
 							// HTTP/0.9
-							_handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _buffer.sliceFromMark(), null);
+							_handler.startRequest(_tok0, _buffer.sliceFromMark(), null);
 							_persistent=false;
 							_state=STATE_SEEKING_EOF;
 							_handler.headerComplete();
@@ -376,14 +380,15 @@
 							{
 								_eol=ch;
 								_state=STATE_HEADER;
-								_tok0.setPutIndex(_tok0.getIndex());
+//								_tok0.setPutIndex(_tok0.getIndex());
+								_tok0 = "";
 								_tok1.setPutIndex(_tok1.getIndex());
 								_multiLineValue=null;
 							}
 							else
 							{
 								// HTTP/0.9
-								_handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1, null);
+								_handler.startRequest(_tok0, _tok1, null);
 								_persistent=false;
 								_state=STATE_SEEKING_EOF;
 								_handler.headerComplete();
@@ -396,16 +401,17 @@
 					case STATE_FIELD2:
 						if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
 						{
-							Buffer version;
-							if (_responseStatus>0)
+							String version;
+							if (_responseStatus > 0)
 //								_handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,_buffer.sliceFromMark());
-								version = HttpVersions.CACHE.lookup(_tok0);
+								version = _tok0;
 							else
-								_handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1, version=HttpVersions.CACHE.lookup(_buffer.sliceFromMark()));
+								_handler.startRequest(_tok0, _tok1, version=_buffer.sliceFromMark().toString());
 							_eol=ch;
-							_persistent=HttpVersions.CACHE.getOrdinal(version)>=HttpVersions.HTTP_1_1_ORDINAL;
+							_persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL;
 							_state=STATE_HEADER;
-							_tok0.setPutIndex(_tok0.getIndex());
+//							_tok0.setPutIndex(_tok0.getIndex());
+							_tok0 = "";
 							_tok1.setPutIndex(_tok1.getIndex());
 							_multiLineValue=null;
 							continue;
@@ -507,7 +513,8 @@
 									}
 
 									_handler.parsedHeader(header, value);
-									_tok0.setPutIndex(_tok0.getIndex());
+//									_tok0.setPutIndex(_tok0.getIndex());
+									_tok0 = "";
 									_tok1.setPutIndex(_tok1.getIndex());
 									_multiLineValue=null;
 								}
@@ -596,14 +603,22 @@
 						{
 							case HttpTokens.CARRIAGE_RETURN:
 							case HttpTokens.LINE_FEED:
-								if (_length > 0)
-									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+								if (_length > 0) {
+//System.out.println("qqqqqqqqqqqqqqqq c "+_tok0);
+//									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+									_tok0 = _buffer.peek(_buffer.markIndex(), _length).toString();
+//System.out.println("qqqqqqqqqqqqqqqq d "+_tok0);
+								}
 								_eol=ch;
 								_state=STATE_HEADER;
 								break;
 							case HttpTokens.COLON:
-								if (_length > 0 && _cached==null)
-									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+								if (_length > 0 && _cached==null) {
+//System.out.println("qqqqqqqqqqqqqqqq e "+_tok0);
+//									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+									_tok0 = _buffer.peek(_buffer.markIndex(), _length).toString();
+//System.out.println("qqqqqqqqqqqqqqqq f "+_tok0);
+								}
 								_length=-1;
 								_state=STATE_HEADER_VALUE;
 								break;
@@ -627,14 +642,22 @@
 						{
 							case HttpTokens.CARRIAGE_RETURN:
 							case HttpTokens.LINE_FEED:
-								if (_length > 0)
-									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+								if (_length > 0) {
+//System.out.println("qqqqqqqqqqqqqqqq g "+_tok0);
+//									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+									_tok0 = _buffer.peek(_buffer.markIndex(),_length).toString();
+//System.out.println("qqqqqqqqqqqqqqqq h "+_tok0);
+								}
 								_eol=ch;
 								_state=STATE_HEADER;
 								break;
 							case HttpTokens.COLON:
-								if (_length > 0 && _cached==null)
-									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+								if (_length > 0 && _cached==null) {
+//System.out.println("qqqqqqqqqqqqqqqq i "+_tok0);
+//									_tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
+									_tok0 = _buffer.peek(_buffer.markIndex(),_length).toString();
+//System.out.println("qqqqqqqqqqqqqqqq j "+_tok0);
+								}
 								_length=-1;
 								_state=STATE_HEADER_VALUE;
 								break;
@@ -1041,7 +1064,10 @@
 		if (_header == null)
 		{
 			_header = _buffers.getHeader();
-			_tok0.update(_header);
+//System.out.println("qqqqqqqqqqqqqqqq k "+_tok0);
+//			_tok0.update(_header);
+			_tok0 = "";
+//System.out.println("qqqqqqqqqqqqqqqq l "+_tok0);
 			_tok1.update(_header);
 		}
 		return _header;
@@ -1122,7 +1148,7 @@
 		/**
 		 * This is the method called by parser when the HTTP request line is parsed
 		 */
-		public abstract void startRequest(Buffer method, Buffer url, Buffer version)
+		public abstract void startRequest(String method, Buffer url, String version)
 				throws IOException;
 
 		public void earlyEOF();