changeset 1058:419bf9c03d84

remove HttpGenerator._method
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2016 04:17:22 -0700
parents afc9610dc12e
children 013939bfc9e8
files src/org/eclipse/jetty/http/HttpGenerator.java
diffstat 1 files changed, 91 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
diff -r afc9610dc12e -r 419bf9c03d84 src/org/eclipse/jetty/http/HttpGenerator.java
--- a/src/org/eclipse/jetty/http/HttpGenerator.java	Tue Nov 08 04:05:04 2016 -0700
+++ b/src/org/eclipse/jetty/http/HttpGenerator.java	Tue Nov 08 04:17:22 2016 -0700
@@ -273,23 +273,13 @@
 		}
 	}
 
-	boolean isRequest()
-	{
-		return _method!=null;
-	}
-
-	private boolean isResponse()
-	{
-		return _method==null;
-	}
-
 	public void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException
 	{
 		if (_state != STATE_HEADER)
 			return;
 
 		// handle a reset
-		if (isResponse() && _status==0)
+		if (_status==0)
 			throw new EofException();
 
 		if (_last && !allContentAdded)
@@ -304,101 +294,73 @@
 
 		try
 		{
-			if (isRequest())
+			// Responses
+			if (_version == HttpVersions.HTTP_0_9_ORDINAL)
 			{
-				_persistent = true;
-
-				if (_version == HttpVersions.HTTP_0_9_ORDINAL)
-				{
-					_contentLength = HttpTokens.NO_CONTENT;
-					_header.put(_method);
-					_header.put((byte)' ');
-					_header.put(_uri.getBytes("UTF-8")); // TODO check
-					_header.put(HttpTokens.CRLF);
-					_state = STATE_FLUSHING;
-					_noContent=true;
-					return;
-				}
-				else
-				{
-					_header.put(_method);
-					_header.put((byte)' ');
-					_header.put(_uri.getBytes("UTF-8")); // TODO check
-					_header.put((byte)' ');
-					_header.put(_version==HttpVersions.HTTP_1_0_ORDINAL?HttpVersions.HTTP_1_0_BYTES:HttpVersions.HTTP_1_1_BYTES);
-					_header.put(HttpTokens.CRLF);
-				}
+				_persistent = false;
+				_contentLength = HttpTokens.EOF_CONTENT;
+				_state = STATE_CONTENT;
+				return;
 			}
 			else
 			{
-				// Responses
-				if (_version == HttpVersions.HTTP_0_9_ORDINAL)
+				if (_persistent==null)
+					_persistent = (_version > HttpVersions.HTTP_1_0_ORDINAL);
+
+				// add response line
+				Status status = _status<__status.length?__status[_status]:null;
+
+				if (status==null)
 				{
-					_persistent = false;
-					_contentLength = HttpTokens.EOF_CONTENT;
-					_state = STATE_CONTENT;
-					return;
+					_header.put(HttpVersions.HTTP_1_1_BYTES);
+					_header.put((byte) ' ');
+					_header.put((byte) ('0' + _status / 100));
+					_header.put((byte) ('0' + (_status % 100) / 10));
+					_header.put((byte) ('0' + (_status % 10)));
+					_header.put((byte) ' ');
+					if (_reason==null)
+					{
+						_header.put((byte) ('0' + _status / 100));
+						_header.put((byte) ('0' + (_status % 100) / 10));
+						_header.put((byte) ('0' + (_status % 10)));
+					}
+					else
+						_header.put(_reason);
+					_header.put(HttpTokens.CRLF);
 				}
 				else
 				{
-					if (_persistent==null)
-						_persistent = (_version > HttpVersions.HTTP_1_0_ORDINAL);
-
-					// add response line
-					Status status = _status<__status.length?__status[_status]:null;
-
-					if (status==null)
-					{
-						_header.put(HttpVersions.HTTP_1_1_BYTES);
-						_header.put((byte) ' ');
-						_header.put((byte) ('0' + _status / 100));
-						_header.put((byte) ('0' + (_status % 100) / 10));
-						_header.put((byte) ('0' + (_status % 10)));
-						_header.put((byte) ' ');
-						if (_reason==null)
-						{
-							_header.put((byte) ('0' + _status / 100));
-							_header.put((byte) ('0' + (_status % 100) / 10));
-							_header.put((byte) ('0' + (_status % 10)));
-						}
-						else
-							_header.put(_reason);
-						_header.put(HttpTokens.CRLF);
-					}
+					if (_reason==null)
+						_header.put(status._responseLine);
 					else
 					{
-						if (_reason==null)
-							_header.put(status._responseLine);
-						else
-						{
-							_header.put(status._schemeCode);
-							_header.put(_reason);
-							_header.put(HttpTokens.CRLF);
-						}
+						_header.put(status._schemeCode);
+						_header.put(_reason);
+						_header.put(HttpTokens.CRLF);
 					}
+				}
 
-					if (_status<200 && _status>=100 )
+				if (_status<200 && _status>=100 )
+				{
+					_noContent=true;
+					_content=null;
+					if (_buffer!=null)
+						_buffer.clear();
+					// end the header.
+
+					if (_status!=101 )
 					{
-						_noContent=true;
-						_content=null;
-						if (_buffer!=null)
-							_buffer.clear();
-						// end the header.
-
-						if (_status!=101 )
-						{
-							_header.put(HttpTokens.CRLF);
-							_state = STATE_CONTENT;
-							return;
-						}
+						_header.put(HttpTokens.CRLF);
+						_state = STATE_CONTENT;
+						return;
 					}
-					else if (_status==204 || _status==304)
-					{
-						_noContent=true;
-						_content=null;
-						if (_buffer!=null)
-							_buffer.clear();
-					}
+				}
+				else if (_status==204 || _status==304)
+				{
+					_noContent=true;
+					_content=null;
+					if (_buffer!=null)
+						_buffer.clear();
 				}
 			}
 
@@ -449,9 +411,6 @@
 							break;
 
 						case HttpHeaders.CONNECTION_ORDINAL:
-							if (isRequest())
-								field.putTo(_header);
-
 							int connection_value = field.getValueOrdinal();
 							switch (connection_value)
 							{
@@ -468,10 +427,9 @@
 											{
 												case HttpHeaderValues.CLOSE_ORDINAL:
 													close=true;
-													if (isResponse())
-														_persistent = false;
+													_persistent = false;
 													keep_alive=false;
-													if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT)
+													if (!_persistent && _contentLength == HttpTokens.UNKNOWN_CONTENT)
 														_contentLength = HttpTokens.EOF_CONTENT;
 													break;
 
@@ -479,8 +437,7 @@
 													if (_version == HttpVersions.HTTP_1_0_ORDINAL)
 													{
 														keep_alive = true;
-														if (isResponse())
-															_persistent = true;
+														_persistent = true;
 													}
 													break;
 
@@ -507,18 +464,14 @@
 								case HttpHeaderValues.UPGRADE_ORDINAL:
 								{
 									// special case for websocket connection ordering
-									if (isResponse())
-									{
-										field.putTo(_header);
-										continue;
-									}
+									field.putTo(_header);
+									continue;
 								}
 								case HttpHeaderValues.CLOSE_ORDINAL:
 								{
 									close=true;
-									if (isResponse())
-										_persistent=false;
-									if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT)
+									_persistent=false;
+									if (!_persistent && _contentLength == HttpTokens.UNKNOWN_CONTENT)
 										_contentLength = HttpTokens.EOF_CONTENT;
 									break;
 								}
@@ -527,8 +480,7 @@
 									if (_version == HttpVersions.HTTP_1_0_ORDINAL)
 									{
 										keep_alive = true;
-										if (isResponse())
-											_persistent=true;
+										_persistent=true;
 									}
 									break;
 								}
@@ -573,13 +525,13 @@
 					// written yet?
 
 					// Response known not to have a body
-					if (_contentWritten == 0 && isResponse() && (_status < 200 || _status == 204 || _status == 304))
+					if (_contentWritten == 0 && (_status < 200 || _status == 204 || _status == 304))
 						_contentLength = HttpTokens.NO_CONTENT;
 					else if (_last)
 					{
 						// we have seen all the _content there is
 						_contentLength = _contentWritten;
-						if (content_length == null && (isResponse() || _contentLength>0 || content_type ) && !_noContent)
+						if (content_length == null && !_noContent)
 						{
 							// known length but not actually set.
 							_header.put(HttpHeaders.CONTENT_LENGTH_BYTES);
@@ -593,21 +545,16 @@
 					{
 						// No idea, so we must assume that a body is coming
 						_contentLength = (!_persistent || _version < HttpVersions.HTTP_1_1_ORDINAL ) ? HttpTokens.EOF_CONTENT : HttpTokens.CHUNKED_CONTENT;
-						if (isRequest() && _contentLength==HttpTokens.EOF_CONTENT)
-						{
-							_contentLength=HttpTokens.NO_CONTENT;
-							_noContent=true;
-						}
 					}
 					break;
 
 				case HttpTokens.NO_CONTENT:
-					if (content_length == null && isResponse() && _status >= 200 && _status != 204 && _status != 304)
+					if (content_length == null && _status >= 200 && _status != 204 && _status != 304)
 						_header.put(CONTENT_LENGTH_0);
 					break;
 
 				case HttpTokens.EOF_CONTENT:
-					_persistent = isRequest();
+					_persistent = false;
 					break;
 
 				case HttpTokens.CHUNKED_CONTENT:
@@ -641,37 +588,34 @@
 				_persistent=false;
 			}
 
-			if (isResponse())
+			if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL))
 			{
-				if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL))
+				_header.put(CONNECTION_CLOSE);
+				if (connection!=null)
 				{
-					_header.put(CONNECTION_CLOSE);
-					if (connection!=null)
-					{
-						_header.setPutIndex(_header.putIndex()-2);
-						_header.put((byte)',');
-						_header.put(connection.toString().getBytes());
-						_header.put(CRLF);
-					}
-				}
-				else if (keep_alive)
-				{
-					_header.put(CONNECTION_KEEP_ALIVE);
-					if (connection!=null)
-					{
-						_header.setPutIndex(_header.putIndex()-2);
-						_header.put((byte)',');
-						_header.put(connection.toString().getBytes());
-						_header.put(CRLF);
-					}
-				}
-				else if (connection!=null)
-				{
-					_header.put(CONNECTION_);
+					_header.setPutIndex(_header.putIndex()-2);
+					_header.put((byte)',');
 					_header.put(connection.toString().getBytes());
 					_header.put(CRLF);
 				}
 			}
+			else if (keep_alive)
+			{
+				_header.put(CONNECTION_KEEP_ALIVE);
+				if (connection!=null)
+				{
+					_header.setPutIndex(_header.putIndex()-2);
+					_header.put((byte)',');
+					_header.put(connection.toString().getBytes());
+					_header.put(CRLF);
+				}
+			}
+			else if (connection!=null)
+			{
+				_header.put(CONNECTION_);
+				_header.put(connection.toString().getBytes());
+				_header.put(CRLF);
+			}
 
 			if (!has_server && _status>199)
 				_header.put(SERVER);
@@ -798,7 +742,7 @@
 							if (_state == STATE_FLUSHING)
 								_state = STATE_END;
 
-							if (_state==STATE_END && _persistent != null && !_persistent && _status!=100 && _method==null)
+							if (_state==STATE_END && _persistent != null && !_persistent && _status!=100)
 								_endp.shutdownOutput();
 						}
 						else
@@ -1016,7 +960,6 @@
 	private int _status = 0;
 	private int _version = HttpVersions.HTTP_1_1_ORDINAL;
 	private JBuffer _reason;
-	private JBuffer _method;
 	private String _uri;
 
 	private long _contentWritten = 0;
@@ -1079,7 +1022,7 @@
 
 	public final boolean isIdle()
 	{
-		return _state == STATE_HEADER && _method==null && _status==0;
+		return _state == STATE_HEADER && _status==0;
 	}
 
 	public final boolean isCommitted()
@@ -1109,7 +1052,7 @@
 	{
 		return _persistent!=null
 		?_persistent.booleanValue()
-		:(isRequest()?true:_version>HttpVersions.HTTP_1_0_ORDINAL);
+		:_version>HttpVersions.HTTP_1_0_ORDINAL;
 	}
 
 	public final void setPersistent(boolean persistent)
@@ -1127,8 +1070,6 @@
 		if (_state != STATE_HEADER)
 			throw new IllegalStateException("STATE!=START "+_state);
 		_version = version;
-		if (_version==HttpVersions.HTTP_0_9_ORDINAL && _method!=null)
-			_noContent=true;
 	}
 
 	/* ------------------------------------------------------------ */
@@ -1139,7 +1080,6 @@
 	public final void setResponse(int status, String reason)
 	{
 		if (_state != STATE_HEADER) throw new IllegalStateException("STATE!=START");
-		_method=null;
 		_status = status;
 		if (reason!=null)
 		{