JETTY-1265 Reason field option in client response

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2289 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-09-21 07:20:07 +00:00
parent 4cb511afa4
commit a47bc35e2d
3 changed files with 110 additions and 21 deletions

View File

@ -43,6 +43,7 @@ jetty-7.2-SNAPSHOT
+ JETTY-1256 annotation jars from Orbit
+ JETTY-1261 errant listener usage in StandardDescriptorProcessor
+ JETTY-1263 JDBCSessionIdManager table creation fails on Oracle
+ JETTY-1265 Reason field option in client response
+ JETTY-1266 Destroy sessions before filters/servlets
+ JETTY-1268 Form Auth saves POST data
+ JETTY-1269 Improve log multithreadedness

View File

@ -29,10 +29,11 @@ import org.eclipse.jetty.util.log.Log;
public class HttpParser implements Parser
{
// States
public static final int STATE_START=-13;
public static final int STATE_FIELD0=-12;
public static final int STATE_SPACE1=-11;
public static final int STATE_FIELD1=-10;
public static final int STATE_START=-14;
public static final int STATE_FIELD0=-13;
public static final int STATE_SPACE1=-12;
public static final int STATE_STATUS=-11;
public static final int STATE_URI=-10;
public static final int STATE_SPACE2=-9;
public static final int STATE_END0=-8;
public static final int STATE_END1=-7;
@ -352,6 +353,7 @@ public class HttpParser implements Parser
if (ch == HttpTokens.SPACE)
{
_tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1);
_responseStatus=HttpVersions.CACHE.get(_tok0)==null?-1:0;
_state=STATE_SPACE1;
continue;
}
@ -365,7 +367,13 @@ public class HttpParser implements Parser
if (ch > HttpTokens.SPACE || ch<0)
{
_buffer.mark();
_state=STATE_FIELD1;
if (_responseStatus>=0)
{
_state=STATE_STATUS;
_responseStatus=ch-'0';
}
else
_state=STATE_URI;
}
else if (ch < HttpTokens.SPACE)
{
@ -373,7 +381,34 @@ public class HttpParser implements Parser
}
break;
case STATE_FIELD1:
case STATE_STATUS:
if (ch == HttpTokens.SPACE)
{
_tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1);
_state=STATE_SPACE2;
continue;
}
else if (ch>='0' && ch<='9')
{
_responseStatus=_responseStatus*10+(ch-'0');
continue;
}
else if (ch < HttpTokens.SPACE && ch>=0)
{
_handler.startResponse(HttpMethods.CACHE.lookup(_tok0), _responseStatus, null);
_eol=ch;
_state=STATE_HEADER;
_tok0.setPutIndex(_tok0.getIndex());
_tok1.setPutIndex(_tok1.getIndex());
_multiLineValue=null;
continue;
}
// not a digit, so must be a URI
_state=STATE_URI;
_responseStatus=-1;
break;
case STATE_URI:
if (ch == HttpTokens.SPACE)
{
_tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1);
@ -400,28 +435,34 @@ public class HttpParser implements Parser
}
else if (ch < HttpTokens.SPACE)
{
// HTTP/0.9
_handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1, null);
_state=STATE_END;
_handler.headerComplete();
_handler.messageComplete(_contentPosition);
return total_filled;
if (_responseStatus>0)
{
_handler.startResponse(HttpMethods.CACHE.lookup(_tok0), _responseStatus, null);
_eol=ch;
_state=STATE_HEADER;
_tok0.setPutIndex(_tok0.getIndex());
_tok1.setPutIndex(_tok1.getIndex());
_multiLineValue=null;
}
else
{
// HTTP/0.9
_handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1, null);
_state=STATE_END;
_handler.headerComplete();
_handler.messageComplete(_contentPosition);
return total_filled;
}
}
break;
case STATE_FIELD2:
if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
{
// TODO - we really should know if we are parsing request or response!
final Buffer method = HttpMethods.CACHE.lookup(_tok0);
if (method==_tok0 && _tok1.length()==3 && Character.isDigit(_tok1.peek()))
{
_responseStatus = BufferUtil.toInt(_tok1);
if (_responseStatus>0)
_handler.startResponse(HttpVersions.CACHE.lookup(_tok0), _responseStatus,_buffer.sliceFromMark());
}
else
_handler.startRequest(method, _tok1,HttpVersions.CACHE.lookup(_buffer.sliceFromMark()));
_handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1,HttpVersions.CACHE.lookup(_buffer.sliceFromMark()));
_eol=ch;
_state=STATE_HEADER;
_tok0.setPutIndex(_tok0.getIndex());

View File

@ -429,6 +429,53 @@ public class HttpParserTest
assertTrue(messageCompleted);
}
@Test
public void testResponseParse3() throws Exception
{
StringEndPoint io=new StringEndPoint();
io.setInput(
"HTTP/1.1 200\015\012"
+ "Content-Length: 10\015\012"
+ "Content-Type: text/plain\015\012"
+ "\015\012"
+ "0123456789\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse();
assertEquals("HTTP/1.1", f0);
assertEquals("200", f1);
assertEquals(null, f2);
assertEquals(_content.length(), 10);
assertTrue(headerCompleted);
assertTrue(messageCompleted);
}
@Test
public void testResponseParse4() throws Exception
{
StringEndPoint io=new StringEndPoint();
io.setInput(
"HTTP/1.1 200 \015\012"
+ "Content-Length: 10\015\012"
+ "Content-Type: text/plain\015\012"
+ "\015\012"
+ "0123456789\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse();
assertEquals("HTTP/1.1", f0);
assertEquals("200", f1);
assertEquals(null, f2);
assertEquals(_content.length(), 10);
assertTrue(headerCompleted);
assertTrue(messageCompleted);
}
private String _content;
private String f0;
private String f1;
@ -509,7 +556,7 @@ public class HttpParserTest
request=false;
f0 = version.toString();
f1 = Integer.toString(status);
f2 = reason.toString();
f2 = reason==null?null:reason.toString();
fields=new HttpFields();
hdr= new String[9];