mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-28 10:59:19 +00:00
jetty-9 first HTTP requests handled and served
This commit is contained in:
parent
9e8b2f1aad
commit
d7729422f6
@ -925,7 +925,7 @@ public class HttpParser
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s{s=%d,c=%d}",
|
||||
return String.format("%s{s=%s,c=%d}",
|
||||
getClass().getSimpleName(),
|
||||
_state,
|
||||
_contentLength);
|
||||
|
@ -28,6 +28,7 @@ import org.eclipse.jetty.io.AsyncConnection;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||
import org.eclipse.jetty.server.Connector.Statistics;
|
||||
import org.eclipse.jetty.util.component.AggregateLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
@ -62,7 +63,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
|
||||
private int _acceptors = 1;
|
||||
private int _acceptorPriorityOffset = 0;
|
||||
private boolean _reuseAddress = true;
|
||||
private ByteBufferPool _byteBufferPool;
|
||||
private ByteBufferPool _byteBufferPool=new StandardByteBufferPool(); // TODO should this be server wide? or a thread local one?
|
||||
|
||||
private final Statistics _stats = new ConnectionStatistics();
|
||||
|
||||
@ -399,7 +400,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
|
||||
try
|
||||
{
|
||||
current.setPriority(old_priority - _acceptorPriorityOffset);
|
||||
while (isRunning() && getConnection() != null)
|
||||
while (isRunning() && getTransport() != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -453,11 +454,10 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
|
||||
_name = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void connectionOpened(AsyncConnection connection)
|
||||
{
|
||||
connection.onOpen();
|
||||
_stats.connectionOpened();
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,10 @@ public abstract class AbstractHttpConnector extends AbstractConnector implements
|
||||
private String _forwardedCipherSuiteHeader;
|
||||
private String _forwardedSslSessionIdHeader;
|
||||
|
||||
private int _requestHeaderSize;
|
||||
private int _requestBufferSize;
|
||||
private int _responseHeaderSize;
|
||||
private int _responseBufferSize;
|
||||
|
||||
private ByteBufferPool _byteBufferPool;
|
||||
private int _requestHeaderSize=6*1024;;
|
||||
private int _requestBufferSize=16*1024;
|
||||
private int _responseHeaderSize=6*1024;
|
||||
private int _responseBufferSize=16*1024;
|
||||
|
||||
@Override
|
||||
public int getRequestHeaderSize()
|
||||
@ -77,17 +75,6 @@ public abstract class AbstractHttpConnector extends AbstractConnector implements
|
||||
_responseBufferSize = responseBufferSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBufferPool getByteBufferPool()
|
||||
{
|
||||
return _byteBufferPool;
|
||||
}
|
||||
|
||||
public void setByteBufferPool(ByteBufferPool byteBufferPool)
|
||||
{
|
||||
_byteBufferPool = byteBufferPool;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void customize(Request request) throws IOException
|
||||
|
@ -90,7 +90,7 @@ public interface Connector extends LifeCycle
|
||||
/**
|
||||
* @return the underlying socket, channel, buffer etc. for the connector.
|
||||
*/
|
||||
Object getConnection();
|
||||
Object getTransport();
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -83,6 +83,8 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
super(endpoint,connector.getServer().getThreadPool());
|
||||
_connector = connector;
|
||||
_bufferPool=_connector.getByteBufferPool();
|
||||
if (_bufferPool==null)
|
||||
new Throwable().printStackTrace();
|
||||
|
||||
_server = server;
|
||||
|
||||
@ -90,7 +92,16 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
|
||||
_parser = new HttpParser(_channel.getRequestHandler());
|
||||
_generator = new HttpGenerator();
|
||||
LOG.debug("New HTTP Connection {}",this);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void onOpen()
|
||||
{
|
||||
LOG.debug("Opened HTTP Connection {}",this);
|
||||
super.onOpen();
|
||||
scheduleOnReadable();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@ -172,6 +183,7 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
{
|
||||
AsyncConnection connection = this;
|
||||
boolean progress=true;
|
||||
boolean suspended=false;
|
||||
|
||||
try
|
||||
{
|
||||
@ -189,6 +201,9 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
?_bufferPool.acquire(_connector.getRequestBufferSize(),false)
|
||||
:_bufferPool.acquire(_connector.getRequestHeaderSize(),false);
|
||||
|
||||
int filled=getEndPoint().fill(_requestBuffer);
|
||||
System.err.println("filled="+filled+" to "+BufferUtil.toDetailString(_requestBuffer)+" from "+getEndPoint());
|
||||
|
||||
// If we parse to an event, call the connection
|
||||
if (BufferUtil.hasContent(_requestBuffer) && _parser.parseNext(_requestBuffer))
|
||||
{
|
||||
@ -243,6 +258,7 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
// exit the while loop by setting progress to false
|
||||
LOG.debug("suspended {}",this);
|
||||
progress=false;
|
||||
suspended=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -254,11 +270,11 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
finally
|
||||
{
|
||||
setCurrentConnection(null);
|
||||
|
||||
if (!getEndPoint().isInputShutdown() && !suspended)
|
||||
scheduleOnReadable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void send(HttpGenerator.ResponseInfo info, ByteBuffer content) throws IOException
|
||||
{
|
||||
@ -348,7 +364,13 @@ public class HttpConnection extends AbstractAsyncConnection
|
||||
preparedBefore=_generator.getContentPrepared();
|
||||
|
||||
if (_generator.isComplete())
|
||||
{
|
||||
/* TODO ??
|
||||
if (Action.COMPLETE==action)
|
||||
return 0;
|
||||
*/
|
||||
throw new EofException();
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ public class LocalConnector extends AbstractConnector
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getConnection()
|
||||
public Object getTransport()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class Response implements HttpServletResponse
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(Response.class);
|
||||
|
||||
public enum Output {NONE,STREAM,WRITER}
|
||||
public enum OutputState {NONE,STREAM,WRITER}
|
||||
|
||||
/**
|
||||
* If a header name starts with this string, the header (stripped of the prefix)
|
||||
@ -73,7 +73,7 @@ public class Response implements HttpServletResponse
|
||||
private MimeTypes.Type _mimeType;
|
||||
private String _characterEncoding;
|
||||
private String _contentType;
|
||||
private Output _outputState;
|
||||
private OutputState _outputState=OutputState.NONE;
|
||||
private PrintWriter _writer;
|
||||
private long _contentLength=-1;
|
||||
|
||||
@ -103,7 +103,7 @@ public class Response implements HttpServletResponse
|
||||
_characterEncoding=null;
|
||||
_contentType=null;
|
||||
_writer=null;
|
||||
_outputState=Output.NONE;
|
||||
_outputState=OutputState.NONE;
|
||||
_contentLength=-1;
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ public class Response implements HttpServletResponse
|
||||
setHeader(HttpHeader.CONTENT_TYPE,null);
|
||||
setHeader(HttpHeader.CONTENT_LENGTH,null);
|
||||
|
||||
_outputState=Output.NONE;
|
||||
_outputState=OutputState.NONE;
|
||||
setStatus(code,message);
|
||||
|
||||
if (message==null)
|
||||
@ -717,24 +717,24 @@ public class Response implements HttpServletResponse
|
||||
@Override
|
||||
public ServletOutputStream getOutputStream() throws IOException
|
||||
{
|
||||
if (_outputState==Output.WRITER)
|
||||
if (_outputState==OutputState.WRITER)
|
||||
throw new IllegalStateException("WRITER");
|
||||
|
||||
ServletOutputStream out = _channel.getOutputStream();
|
||||
_outputState=Output.STREAM;
|
||||
_outputState=OutputState.STREAM;
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isWriting()
|
||||
{
|
||||
return _outputState==Output.WRITER;
|
||||
return _outputState==OutputState.WRITER;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isOutputing()
|
||||
{
|
||||
return _outputState!=Output.NONE;
|
||||
return _outputState!=OutputState.NONE;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@ -744,7 +744,7 @@ public class Response implements HttpServletResponse
|
||||
@Override
|
||||
public PrintWriter getWriter() throws IOException
|
||||
{
|
||||
if (_outputState==Output.STREAM)
|
||||
if (_outputState==OutputState.STREAM)
|
||||
throw new IllegalStateException("STREAM");
|
||||
|
||||
/* if there is no writer yet */
|
||||
@ -764,7 +764,7 @@ public class Response implements HttpServletResponse
|
||||
/* construct Writer using correct encoding */
|
||||
_writer = _channel.getPrintWriter(encoding);
|
||||
}
|
||||
_outputState=Output.WRITER;
|
||||
_outputState=OutputState.WRITER;
|
||||
return _writer;
|
||||
}
|
||||
|
||||
@ -842,7 +842,7 @@ public class Response implements HttpServletResponse
|
||||
if (_channel.isIncluding())
|
||||
return;
|
||||
|
||||
if (_outputState==Output.NONE && !isCommitted())
|
||||
if (_outputState==OutputState.NONE && !isCommitted())
|
||||
{
|
||||
if (encoding==null)
|
||||
{
|
||||
@ -992,7 +992,7 @@ public class Response implements HttpServletResponse
|
||||
resetBuffer();
|
||||
|
||||
_writer=null;
|
||||
_outputState=Output.NONE;
|
||||
_outputState=OutputState.NONE;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@ -1038,7 +1038,7 @@ public class Response implements HttpServletResponse
|
||||
_locale = locale;
|
||||
_fields.put(HttpHeader.CONTENT_LANGUAGE,locale.toString().replace('_','-'));
|
||||
|
||||
if (_outputState!=Output.NONE )
|
||||
if (_outputState!=OutputState.NONE )
|
||||
return;
|
||||
|
||||
if (_channel.getRequest().getContext()==null)
|
||||
|
@ -61,8 +61,6 @@ import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
public class SelectChannelConnector extends AbstractHttpConnector
|
||||
{
|
||||
protected ServerSocketChannel _acceptChannel;
|
||||
private int _lowResourcesConnections;
|
||||
private int _lowResourcesMaxIdleTime;
|
||||
private int _localPort=-1;
|
||||
|
||||
private final SelectorManager _manager = new ConnectorSelectorManager();
|
||||
@ -100,6 +98,7 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
synchronized(this)
|
||||
@ -130,12 +129,14 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public synchronized Object getConnection()
|
||||
@Override
|
||||
public synchronized Object getTransport()
|
||||
{
|
||||
return _acceptChannel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
@Override
|
||||
public int getLocalPort()
|
||||
{
|
||||
synchronized(this)
|
||||
@ -145,6 +146,7 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void open() throws IOException
|
||||
{
|
||||
synchronized(this)
|
||||
@ -178,27 +180,6 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
||||
super.setMaxIdleTime(maxIdleTime);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return the lowResourcesConnections
|
||||
*/
|
||||
public int getLowResourcesConnections()
|
||||
{
|
||||
return _lowResourcesConnections;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the number of connections, which if exceeded places this manager in low resources state.
|
||||
* This is not an exact measure as the connection count is averaged over the select sets.
|
||||
* @param lowResourcesConnections the number of connections
|
||||
* @see #setLowResourcesMaxIdleTime(int)
|
||||
*/
|
||||
public void setLowResourcesConnections(int lowResourcesConnections)
|
||||
{
|
||||
_lowResourcesConnections=lowResourcesConnections;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see org.eclipse.jetty.server.server.AbstractConnector#doStart()
|
||||
|
Loading…
x
Reference in New Issue
Block a user