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
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("%s{s=%d,c=%d}",
|
return String.format("%s{s=%s,c=%d}",
|
||||||
getClass().getSimpleName(),
|
getClass().getSimpleName(),
|
||||||
_state,
|
_state,
|
||||||
_contentLength);
|
_contentLength);
|
||||||
|
@ -28,6 +28,7 @@ import org.eclipse.jetty.io.AsyncConnection;
|
|||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
import org.eclipse.jetty.io.EofException;
|
import org.eclipse.jetty.io.EofException;
|
||||||
|
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||||
import org.eclipse.jetty.server.Connector.Statistics;
|
import org.eclipse.jetty.server.Connector.Statistics;
|
||||||
import org.eclipse.jetty.util.component.AggregateLifeCycle;
|
import org.eclipse.jetty.util.component.AggregateLifeCycle;
|
||||||
import org.eclipse.jetty.util.component.Dumpable;
|
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 _acceptors = 1;
|
||||||
private int _acceptorPriorityOffset = 0;
|
private int _acceptorPriorityOffset = 0;
|
||||||
private boolean _reuseAddress = true;
|
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();
|
private final Statistics _stats = new ConnectionStatistics();
|
||||||
|
|
||||||
@ -399,7 +400,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
current.setPriority(old_priority - _acceptorPriorityOffset);
|
current.setPriority(old_priority - _acceptorPriorityOffset);
|
||||||
while (isRunning() && getConnection() != null)
|
while (isRunning() && getTransport() != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -453,11 +454,10 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
|
|||||||
_name = name;
|
_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
protected void connectionOpened(AsyncConnection connection)
|
protected void connectionOpened(AsyncConnection connection)
|
||||||
{
|
{
|
||||||
|
connection.onOpen();
|
||||||
_stats.connectionOpened();
|
_stats.connectionOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +26,10 @@ public abstract class AbstractHttpConnector extends AbstractConnector implements
|
|||||||
private String _forwardedCipherSuiteHeader;
|
private String _forwardedCipherSuiteHeader;
|
||||||
private String _forwardedSslSessionIdHeader;
|
private String _forwardedSslSessionIdHeader;
|
||||||
|
|
||||||
private int _requestHeaderSize;
|
private int _requestHeaderSize=6*1024;;
|
||||||
private int _requestBufferSize;
|
private int _requestBufferSize=16*1024;
|
||||||
private int _responseHeaderSize;
|
private int _responseHeaderSize=6*1024;
|
||||||
private int _responseBufferSize;
|
private int _responseBufferSize=16*1024;
|
||||||
|
|
||||||
private ByteBufferPool _byteBufferPool;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRequestHeaderSize()
|
public int getRequestHeaderSize()
|
||||||
@ -77,17 +75,6 @@ public abstract class AbstractHttpConnector extends AbstractConnector implements
|
|||||||
_responseBufferSize = responseBufferSize;
|
_responseBufferSize = responseBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ByteBufferPool getByteBufferPool()
|
|
||||||
{
|
|
||||||
return _byteBufferPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setByteBufferPool(ByteBufferPool byteBufferPool)
|
|
||||||
{
|
|
||||||
_byteBufferPool = byteBufferPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
public void customize(Request request) throws IOException
|
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.
|
* @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());
|
super(endpoint,connector.getServer().getThreadPool());
|
||||||
_connector = connector;
|
_connector = connector;
|
||||||
_bufferPool=_connector.getByteBufferPool();
|
_bufferPool=_connector.getByteBufferPool();
|
||||||
|
if (_bufferPool==null)
|
||||||
|
new Throwable().printStackTrace();
|
||||||
|
|
||||||
_server = server;
|
_server = server;
|
||||||
|
|
||||||
@ -90,7 +92,16 @@ public class HttpConnection extends AbstractAsyncConnection
|
|||||||
|
|
||||||
_parser = new HttpParser(_channel.getRequestHandler());
|
_parser = new HttpParser(_channel.getRequestHandler());
|
||||||
_generator = new HttpGenerator();
|
_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;
|
AsyncConnection connection = this;
|
||||||
boolean progress=true;
|
boolean progress=true;
|
||||||
|
boolean suspended=false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -188,6 +200,9 @@ public class HttpConnection extends AbstractAsyncConnection
|
|||||||
_requestBuffer=_parser.isInContent()
|
_requestBuffer=_parser.isInContent()
|
||||||
?_bufferPool.acquire(_connector.getRequestBufferSize(),false)
|
?_bufferPool.acquire(_connector.getRequestBufferSize(),false)
|
||||||
:_bufferPool.acquire(_connector.getRequestHeaderSize(),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 we parse to an event, call the connection
|
||||||
if (BufferUtil.hasContent(_requestBuffer) && _parser.parseNext(_requestBuffer))
|
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
|
// exit the while loop by setting progress to false
|
||||||
LOG.debug("suspended {}",this);
|
LOG.debug("suspended {}",this);
|
||||||
progress=false;
|
progress=false;
|
||||||
|
suspended=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,11 +270,11 @@ public class HttpConnection extends AbstractAsyncConnection
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
setCurrentConnection(null);
|
setCurrentConnection(null);
|
||||||
|
if (!getEndPoint().isInputShutdown() && !suspended)
|
||||||
|
scheduleOnReadable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
private void send(HttpGenerator.ResponseInfo info, ByteBuffer content) throws IOException
|
private void send(HttpGenerator.ResponseInfo info, ByteBuffer content) throws IOException
|
||||||
{
|
{
|
||||||
@ -348,8 +364,14 @@ public class HttpConnection extends AbstractAsyncConnection
|
|||||||
preparedBefore=_generator.getContentPrepared();
|
preparedBefore=_generator.getContentPrepared();
|
||||||
|
|
||||||
if (_generator.isComplete())
|
if (_generator.isComplete())
|
||||||
|
{
|
||||||
|
/* TODO ??
|
||||||
|
if (Action.COMPLETE==action)
|
||||||
|
return 0;
|
||||||
|
*/
|
||||||
throw new EofException();
|
throw new EofException();
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// block if the last write is not complete
|
// block if the last write is not complete
|
||||||
|
@ -38,7 +38,7 @@ public class LocalConnector extends AbstractConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getConnection()
|
public Object getTransport()
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class Response implements HttpServletResponse
|
|||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(Response.class);
|
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)
|
* 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 MimeTypes.Type _mimeType;
|
||||||
private String _characterEncoding;
|
private String _characterEncoding;
|
||||||
private String _contentType;
|
private String _contentType;
|
||||||
private Output _outputState;
|
private OutputState _outputState=OutputState.NONE;
|
||||||
private PrintWriter _writer;
|
private PrintWriter _writer;
|
||||||
private long _contentLength=-1;
|
private long _contentLength=-1;
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ public class Response implements HttpServletResponse
|
|||||||
_characterEncoding=null;
|
_characterEncoding=null;
|
||||||
_contentType=null;
|
_contentType=null;
|
||||||
_writer=null;
|
_writer=null;
|
||||||
_outputState=Output.NONE;
|
_outputState=OutputState.NONE;
|
||||||
_contentLength=-1;
|
_contentLength=-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ public class Response implements HttpServletResponse
|
|||||||
setHeader(HttpHeader.CONTENT_TYPE,null);
|
setHeader(HttpHeader.CONTENT_TYPE,null);
|
||||||
setHeader(HttpHeader.CONTENT_LENGTH,null);
|
setHeader(HttpHeader.CONTENT_LENGTH,null);
|
||||||
|
|
||||||
_outputState=Output.NONE;
|
_outputState=OutputState.NONE;
|
||||||
setStatus(code,message);
|
setStatus(code,message);
|
||||||
|
|
||||||
if (message==null)
|
if (message==null)
|
||||||
@ -717,24 +717,24 @@ public class Response implements HttpServletResponse
|
|||||||
@Override
|
@Override
|
||||||
public ServletOutputStream getOutputStream() throws IOException
|
public ServletOutputStream getOutputStream() throws IOException
|
||||||
{
|
{
|
||||||
if (_outputState==Output.WRITER)
|
if (_outputState==OutputState.WRITER)
|
||||||
throw new IllegalStateException("WRITER");
|
throw new IllegalStateException("WRITER");
|
||||||
|
|
||||||
ServletOutputStream out = _channel.getOutputStream();
|
ServletOutputStream out = _channel.getOutputStream();
|
||||||
_outputState=Output.STREAM;
|
_outputState=OutputState.STREAM;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public boolean isWriting()
|
public boolean isWriting()
|
||||||
{
|
{
|
||||||
return _outputState==Output.WRITER;
|
return _outputState==OutputState.WRITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public boolean isOutputing()
|
public boolean isOutputing()
|
||||||
{
|
{
|
||||||
return _outputState!=Output.NONE;
|
return _outputState!=OutputState.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@ -744,7 +744,7 @@ public class Response implements HttpServletResponse
|
|||||||
@Override
|
@Override
|
||||||
public PrintWriter getWriter() throws IOException
|
public PrintWriter getWriter() throws IOException
|
||||||
{
|
{
|
||||||
if (_outputState==Output.STREAM)
|
if (_outputState==OutputState.STREAM)
|
||||||
throw new IllegalStateException("STREAM");
|
throw new IllegalStateException("STREAM");
|
||||||
|
|
||||||
/* if there is no writer yet */
|
/* if there is no writer yet */
|
||||||
@ -764,7 +764,7 @@ public class Response implements HttpServletResponse
|
|||||||
/* construct Writer using correct encoding */
|
/* construct Writer using correct encoding */
|
||||||
_writer = _channel.getPrintWriter(encoding);
|
_writer = _channel.getPrintWriter(encoding);
|
||||||
}
|
}
|
||||||
_outputState=Output.WRITER;
|
_outputState=OutputState.WRITER;
|
||||||
return _writer;
|
return _writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,7 +842,7 @@ public class Response implements HttpServletResponse
|
|||||||
if (_channel.isIncluding())
|
if (_channel.isIncluding())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_outputState==Output.NONE && !isCommitted())
|
if (_outputState==OutputState.NONE && !isCommitted())
|
||||||
{
|
{
|
||||||
if (encoding==null)
|
if (encoding==null)
|
||||||
{
|
{
|
||||||
@ -992,7 +992,7 @@ public class Response implements HttpServletResponse
|
|||||||
resetBuffer();
|
resetBuffer();
|
||||||
|
|
||||||
_writer=null;
|
_writer=null;
|
||||||
_outputState=Output.NONE;
|
_outputState=OutputState.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@ -1038,7 +1038,7 @@ public class Response implements HttpServletResponse
|
|||||||
_locale = locale;
|
_locale = locale;
|
||||||
_fields.put(HttpHeader.CONTENT_LANGUAGE,locale.toString().replace('_','-'));
|
_fields.put(HttpHeader.CONTENT_LANGUAGE,locale.toString().replace('_','-'));
|
||||||
|
|
||||||
if (_outputState!=Output.NONE )
|
if (_outputState!=OutputState.NONE )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_channel.getRequest().getContext()==null)
|
if (_channel.getRequest().getContext()==null)
|
||||||
|
@ -61,8 +61,6 @@ import org.eclipse.jetty.util.thread.ThreadPool;
|
|||||||
public class SelectChannelConnector extends AbstractHttpConnector
|
public class SelectChannelConnector extends AbstractHttpConnector
|
||||||
{
|
{
|
||||||
protected ServerSocketChannel _acceptChannel;
|
protected ServerSocketChannel _acceptChannel;
|
||||||
private int _lowResourcesConnections;
|
|
||||||
private int _lowResourcesMaxIdleTime;
|
|
||||||
private int _localPort=-1;
|
private int _localPort=-1;
|
||||||
|
|
||||||
private final SelectorManager _manager = new ConnectorSelectorManager();
|
private final SelectorManager _manager = new ConnectorSelectorManager();
|
||||||
@ -100,6 +98,7 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
synchronized(this)
|
synchronized(this)
|
||||||
@ -130,12 +129,14 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public synchronized Object getConnection()
|
@Override
|
||||||
|
public synchronized Object getTransport()
|
||||||
{
|
{
|
||||||
return _acceptChannel;
|
return _acceptChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------------- */
|
||||||
|
@Override
|
||||||
public int getLocalPort()
|
public int getLocalPort()
|
||||||
{
|
{
|
||||||
synchronized(this)
|
synchronized(this)
|
||||||
@ -145,6 +146,7 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
public void open() throws IOException
|
public void open() throws IOException
|
||||||
{
|
{
|
||||||
synchronized(this)
|
synchronized(this)
|
||||||
@ -178,27 +180,6 @@ public class SelectChannelConnector extends AbstractHttpConnector
|
|||||||
super.setMaxIdleTime(maxIdleTime);
|
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()
|
* @see org.eclipse.jetty.server.server.AbstractConnector#doStart()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user