jetty-9 progress on reading input

This commit is contained in:
Greg Wilkins 2012-05-15 16:33:30 +02:00
parent 1c319703b9
commit 4e3826210b
3 changed files with 81 additions and 55 deletions

View File

@ -309,6 +309,8 @@ public abstract class HttpChannel
/* ------------------------------------------------------------ */
protected void handleRequest() throws IOException
{
System.err.println("handleRequest");
boolean error = false;
String threadName=null;
@ -506,6 +508,7 @@ public abstract class HttpChannel
{
synchronized (_inputQ.lock())
{
System.err.println("read "+len+" "+_inputQ);
ByteBuffer content=null;
while(content==null)
{
@ -525,6 +528,8 @@ public abstract class HttpChannel
blockForContent();
}
}
System.err.println("reading "+len+" "+BufferUtil.toDetailString(content));
int l=Math.min(len,content.remaining());
content.get(b,off,l);
@ -598,58 +603,60 @@ public abstract class HttpChannel
@Override
public boolean parsedHeader(HttpHeader header, String name, String value) throws IOException
{
switch (header)
if (header!=null)
{
case HOST:
// TODO check if host matched a host in the URI.
_host = true;
break;
switch (header)
{
case HOST:
// TODO check if host matched a host in the URI.
_host = true;
break;
case EXPECT:
HttpHeaderValue expect = HttpHeaderValue.CACHE.get(value);
switch(expect==null?HttpHeaderValue.UNKNOWN:expect)
{
case CONTINUE:
_expect100Continue=true;
break;
case EXPECT:
HttpHeaderValue expect = HttpHeaderValue.CACHE.get(value);
switch(expect==null?HttpHeaderValue.UNKNOWN:expect)
{
case CONTINUE:
_expect100Continue=true;
break;
case PROCESSING:
_expect102Processing=true;
break;
case PROCESSING:
_expect102Processing=true;
break;
default:
String[] values = value.toString().split(",");
for (int i=0;values!=null && i<values.length;i++)
{
expect=HttpHeaderValue.CACHE.get(values[i].trim());
if (expect==null)
_expect=true;
else
default:
String[] values = value.toString().split(",");
for (int i=0;values!=null && i<values.length;i++)
{
switch(expect)
expect=HttpHeaderValue.CACHE.get(values[i].trim());
if (expect==null)
_expect=true;
else
{
case CONTINUE:
_expect100Continue=true;
break;
case PROCESSING:
_expect102Processing=true;
break;
default:
_expect=true;
switch(expect)
{
case CONTINUE:
_expect100Continue=true;
break;
case PROCESSING:
_expect102Processing=true;
break;
default:
_expect=true;
}
}
}
}
}
break;
}
break;
case CONTENT_TYPE:
MimeTypes.Type mime=MimeTypes.CACHE.get(value);
String charset=(mime==null)?MimeTypes.getCharsetFromContentType(value):mime.getCharset().toString();
if (charset!=null)
_request.setCharacterEncodingUnchecked(charset);
break;
case CONTENT_TYPE:
MimeTypes.Type mime=MimeTypes.CACHE.get(value);
String charset=(mime==null)?MimeTypes.getCharsetFromContentType(value):mime.getCharset().toString();
if (charset!=null)
_request.setCharacterEncodingUnchecked(charset);
break;
}
}
_requestFields.add(name, value);
return false;
}
@ -710,6 +717,7 @@ public abstract class HttpChannel
{
synchronized (_inputQ.lock())
{
System.err.println("CONTENT "+BufferUtil.toDetailString(ref));
_inputQ.add(ref);
}
return true;
@ -719,7 +727,9 @@ public abstract class HttpChannel
public boolean messageComplete(long contentLength) throws IOException
{
synchronized (_inputQ.lock())
{
{
System.err.println("MESSAGE EOF");
_inputEOF=true;
}
return true;

View File

@ -234,9 +234,16 @@ public class HttpConnection extends AbstractAsyncConnection
}
catch (HttpException e)
{
progress=true;
LOG.debug(e);
progress=false;
_channel.sendError(e.getStatus(), e.getReason(), null, true);
}
catch (Exception e)
{
LOG.debug(e);
progress=false;
_channel.sendError(500, e.toString(), e.toString(), true);
}
finally
{
// Return empty request buffer if all has been consumed
@ -272,9 +279,10 @@ public class HttpConnection extends AbstractAsyncConnection
}
}
}
catch(IOException e)
catch(Exception e)
{
LOG.warn(e);
getEndPoint().close();
}
finally
{
@ -580,17 +588,23 @@ public class HttpConnection extends AbstractAsyncConnection
{
try
{
// Wait until we can read
FutureCallback<Void> block=new FutureCallback<>();
getEndPoint().readable(null,block);
block.get();
System.err.println("blockForContent: "+BufferUtil.toDetailString(_requestBuffer));
// Do we have content ready to parse?
if (BufferUtil.isEmpty(_requestBuffer))
{
// Wait until we can read
FutureCallback<Void> block=new FutureCallback<>();
getEndPoint().readable(null,block);
block.get();
// We will need a buffer to read into
if (_requestBuffer==null)
_requestBuffer=_bufferPool.acquire(_connector.getRequestBufferSize(),false);
// We will need a buffer to read into
if (_requestBuffer==null)
_requestBuffer=_bufferPool.acquire(_connector.getRequestBufferSize(),false);
int filled=getEndPoint().fill(_requestBuffer);
LOG.debug("{} filled {}",this,filled);
int filled=getEndPoint().fill(_requestBuffer);
LOG.debug("{} filled {}",this,filled);
}
// If we parse to an event, return
while (BufferUtil.hasContent(_requestBuffer) && _parser.inContentState())

View File

@ -37,6 +37,8 @@ public class HttpInput extends ServletInputStream
public int read() throws IOException
{
int len=_channel.read(_byte,0,1);
if (len>0)
System.err.println("READ "+_byte[0]);
return len<0?len:_byte[0];
}
@ -47,7 +49,7 @@ public class HttpInput extends ServletInputStream
@Override
public int read(byte[] b, int off, int len) throws IOException
{
return _channel.read(_byte,0,1);
return _channel.read(b,off,len);
}
/* ------------------------------------------------------------ */