jetty-9 work in progress
This commit is contained in:
parent
737db225e3
commit
adb1d86ab8
|
@ -61,11 +61,6 @@ public class HttpGenerator
|
|||
boolean isHead();
|
||||
}
|
||||
|
||||
// data
|
||||
private final Info _info;
|
||||
private final RequestInfo _request;
|
||||
private final ResponseInfo _response;
|
||||
|
||||
private State _state = State.START;
|
||||
private EndOfContent _content = EndOfContent.UNKNOWN_CONTENT;
|
||||
|
||||
|
@ -87,21 +82,10 @@ public class HttpGenerator
|
|||
private boolean _needCRLF = false;
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
public HttpGenerator(RequestInfo info)
|
||||
public HttpGenerator()
|
||||
{
|
||||
_info=info;
|
||||
_request=info;
|
||||
_response=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
public HttpGenerator(ResponseInfo info)
|
||||
{
|
||||
_info=info;
|
||||
_request=null;
|
||||
_response=info;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
public void reset()
|
||||
{
|
||||
|
@ -176,40 +160,24 @@ public class HttpGenerator
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return <code>false</code> if the connection should be closed after a request has been read,
|
||||
* <code>true</code> if it should be used for additional requests.
|
||||
* @return A Boolean if persistence has been set, else null
|
||||
*/
|
||||
public boolean isPersistent()
|
||||
public Boolean isPersistent()
|
||||
{
|
||||
return _persistent!=null
|
||||
?_persistent.booleanValue()
|
||||
:(isRequest()?true:_info.getHttpVersion().ordinal()>HttpVersion.HTTP_1_0.ordinal());
|
||||
return _persistent;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setPersistent(boolean persistent)
|
||||
{
|
||||
_persistent=persistent;
|
||||
_persistent=new Boolean(persistent);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpVersion getVersion()
|
||||
{
|
||||
return _info.getHttpVersion();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isWritten()
|
||||
{
|
||||
return _contentPrepared>0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isAllContentWritten()
|
||||
{
|
||||
return _content==EndOfContent.CONTENT_LENGTH && _contentPrepared>=_info.getContentLength();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public long getContentPrepared()
|
||||
|
@ -218,19 +186,7 @@ public class HttpGenerator
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isRequest()
|
||||
{
|
||||
return _request!=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isResponse()
|
||||
{
|
||||
return _response!=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Result generate(ByteBuffer header, ByteBuffer chunk, ByteBuffer buffer, ByteBuffer content, Action action)
|
||||
public Result generate(Info _info, ByteBuffer header, ByteBuffer chunk, ByteBuffer buffer, ByteBuffer content, Action action)
|
||||
{
|
||||
Result result = Result.OK;
|
||||
if (_state==State.END)
|
||||
|
@ -332,7 +288,7 @@ public class HttpGenerator
|
|||
case COMMITTING:
|
||||
case COMMITTING_COMPLETING:
|
||||
{
|
||||
if (isRequest())
|
||||
if (_info instanceof RequestInfo)
|
||||
{
|
||||
if (header==null || header.capacity()<=CHUNK_SIZE)
|
||||
return Result.NEED_HEADER;
|
||||
|
@ -340,12 +296,12 @@ public class HttpGenerator
|
|||
if(_info.getHttpVersion()==HttpVersion.HTTP_0_9)
|
||||
{
|
||||
_noContent=true;
|
||||
generateRequestLine(header);
|
||||
generateRequestLine((RequestInfo)_info,header);
|
||||
_state = State.END;
|
||||
return Result.OK;
|
||||
}
|
||||
_persistent=true;
|
||||
generateRequestLine(header);
|
||||
generateRequestLine((RequestInfo)_info,header);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -370,10 +326,10 @@ public class HttpGenerator
|
|||
if (_persistent==null)
|
||||
_persistent=(_info.getHttpVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal());
|
||||
|
||||
generateResponseLine(header);
|
||||
generateResponseLine(((ResponseInfo)_info),header);
|
||||
|
||||
// Handle 1xx
|
||||
int status=_response.getStatus();
|
||||
int status=((ResponseInfo)_info).getStatus();
|
||||
if (status>=100 && status<200 )
|
||||
{
|
||||
_noContent=true;
|
||||
|
@ -392,7 +348,7 @@ public class HttpGenerator
|
|||
}
|
||||
|
||||
boolean completing=action==Action.COMPLETE||_state==State.COMMITTING_COMPLETING;
|
||||
generateHeaders(header,content,completing);
|
||||
generateHeaders(_info,header,content,completing);
|
||||
_state = completing?State.COMPLETING:State.COMMITTED;
|
||||
|
||||
// handle result
|
||||
|
@ -440,6 +396,7 @@ public class HttpGenerator
|
|||
break;
|
||||
case FLUSH_CONTENT:
|
||||
prepareChunk(chunk,content.remaining());
|
||||
break;
|
||||
case OK:
|
||||
if (BufferUtil.hasContent(buffer))
|
||||
{
|
||||
|
@ -508,28 +465,28 @@ public class HttpGenerator
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void generateRequestLine(ByteBuffer header)
|
||||
private void generateRequestLine(RequestInfo request,ByteBuffer header)
|
||||
{
|
||||
header.put(StringUtil.getBytes(_request.getMethod()));
|
||||
header.put(StringUtil.getBytes(request.getMethod()));
|
||||
header.put((byte)' ');
|
||||
header.put(StringUtil.getBytes(_request.getURI()));
|
||||
switch(_info.getHttpVersion())
|
||||
header.put(StringUtil.getBytes(request.getURI()));
|
||||
switch(request.getHttpVersion())
|
||||
{
|
||||
case HTTP_1_0:
|
||||
case HTTP_1_1:
|
||||
header.put((byte)' ');
|
||||
header.put(_info.getHttpVersion().toBytes());
|
||||
header.put(request.getHttpVersion().toBytes());
|
||||
}
|
||||
header.put(HttpTokens.CRLF);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void generateResponseLine(ByteBuffer header)
|
||||
private void generateResponseLine(ResponseInfo response, ByteBuffer header)
|
||||
{
|
||||
// Look for prepared response line
|
||||
int status=_response.getStatus();
|
||||
int status=response.getStatus();
|
||||
PreparedResponse preprepared = status<__preprepared.length?__preprepared[status]:null;
|
||||
String reason=_response.getReason();
|
||||
String reason=response.getReason();
|
||||
if (preprepared!=null)
|
||||
{
|
||||
if (reason==null)
|
||||
|
@ -574,8 +531,11 @@ public class HttpGenerator
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void generateHeaders(ByteBuffer header,ByteBuffer content,boolean last)
|
||||
private void generateHeaders(Info _info,ByteBuffer header,ByteBuffer content,boolean last)
|
||||
{
|
||||
final RequestInfo _request=(_info instanceof RequestInfo)?(RequestInfo)_info:null;
|
||||
final ResponseInfo _response=(_info instanceof ResponseInfo)?(ResponseInfo)_info:null;
|
||||
|
||||
// default field values
|
||||
boolean has_server = false;
|
||||
HttpFields.Field transfer_encoding=null;
|
||||
|
@ -620,7 +580,7 @@ public class HttpGenerator
|
|||
|
||||
case CONNECTION:
|
||||
{
|
||||
if (isRequest())
|
||||
if (_request!=null)
|
||||
field.putTo(header);
|
||||
|
||||
// Lookup and/or split connection value field
|
||||
|
@ -654,10 +614,12 @@ public class HttpGenerator
|
|||
case CLOSE:
|
||||
{
|
||||
close=true;
|
||||
if (isResponse())
|
||||
if (_response!=null)
|
||||
{
|
||||
_persistent=false;
|
||||
if (!_persistent && isResponse() && _content == EndOfContent.UNKNOWN_CONTENT)
|
||||
_content=EndOfContent.EOF_CONTENT;
|
||||
if (_content == EndOfContent.UNKNOWN_CONTENT)
|
||||
_content=EndOfContent.EOF_CONTENT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -666,7 +628,7 @@ public class HttpGenerator
|
|||
if (_info.getHttpVersion() == HttpVersion.HTTP_1_0)
|
||||
{
|
||||
keep_alive = true;
|
||||
if (isResponse())
|
||||
if (_response!=null)
|
||||
_persistent=true;
|
||||
}
|
||||
break;
|
||||
|
@ -730,14 +692,14 @@ public class HttpGenerator
|
|||
// written yet?
|
||||
|
||||
// Response known not to have a body
|
||||
if (_contentPrepared == 0 && isResponse() && (status < 200 || status == 204 || status == 304))
|
||||
if (_contentPrepared == 0 && _response!=null && (status < 200 || status == 204 || status == 304))
|
||||
_content=EndOfContent.NO_CONTENT;
|
||||
else if (_info.getContentLength()>0)
|
||||
{
|
||||
// we have been given a content length
|
||||
_content=EndOfContent.CONTENT_LENGTH;
|
||||
long content_length = _info.getContentLength();
|
||||
if ((isResponse() || content_length>0 || content_type ) && !_noContent)
|
||||
if ((_response!=null || content_length>0 || content_type ) && !_noContent)
|
||||
{
|
||||
// known length but not actually set.
|
||||
header.put(HttpHeader.CONTENT_LENGTH.getBytesColonSpace());
|
||||
|
@ -752,7 +714,7 @@ public class HttpGenerator
|
|||
long content_length = _contentPrepared+BufferUtil.length(content);
|
||||
|
||||
// Do we need to tell the headers about it
|
||||
if ((isResponse() || content_length>0 || content_type ) && !_noContent)
|
||||
if ((_response!=null || content_length>0 || content_type ) && !_noContent)
|
||||
{
|
||||
header.put(HttpHeader.CONTENT_LENGTH.getBytesColonSpace());
|
||||
BufferUtil.putDecLong(header, content_length);
|
||||
|
@ -763,7 +725,7 @@ public class HttpGenerator
|
|||
{
|
||||
// No idea, so we must assume that a body is coming
|
||||
_content = (!_persistent || _info.getHttpVersion().ordinal() < HttpVersion.HTTP_1_1.ordinal() ) ? EndOfContent.EOF_CONTENT : EndOfContent.CHUNKED_CONTENT;
|
||||
if (isRequest() && _content==EndOfContent.EOF_CONTENT)
|
||||
if (_response!=null && _content==EndOfContent.EOF_CONTENT)
|
||||
{
|
||||
_content=EndOfContent.NO_CONTENT;
|
||||
_noContent=true;
|
||||
|
@ -773,7 +735,7 @@ public class HttpGenerator
|
|||
|
||||
case CONTENT_LENGTH:
|
||||
long content_length = _info.getContentLength();
|
||||
if ((isResponse() || content_length>0 || content_type ) && !_noContent)
|
||||
if ((_response!=null || content_length>0 || content_type ) && !_noContent)
|
||||
{
|
||||
// known length but not actually set.
|
||||
header.put(HttpHeader.CONTENT_LENGTH.getBytesColonSpace());
|
||||
|
@ -783,12 +745,12 @@ public class HttpGenerator
|
|||
break;
|
||||
|
||||
case NO_CONTENT:
|
||||
if (isResponse() && status >= 200 && status != 204 && status != 304)
|
||||
if (_response!=null && status >= 200 && status != 204 && status != 304)
|
||||
header.put(CONTENT_LENGTH_0);
|
||||
break;
|
||||
|
||||
case EOF_CONTENT:
|
||||
_persistent = isRequest();
|
||||
_persistent = _request!=null;
|
||||
break;
|
||||
|
||||
case CHUNKED_CONTENT:
|
||||
|
@ -823,7 +785,7 @@ public class HttpGenerator
|
|||
}
|
||||
|
||||
// If this is a response, work out persistence
|
||||
if (isResponse())
|
||||
if (_response!=null)
|
||||
{
|
||||
if (!_persistent && (close || _info.getHttpVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal()))
|
||||
{
|
||||
|
|
|
@ -85,24 +85,24 @@ public class HttpGeneratorClientTest
|
|||
{
|
||||
ByteBuffer header=BufferUtil.allocate(2048);
|
||||
Info info = new Info("GET","/index.html");
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
info.getHttpFields().add("Host","something");
|
||||
info.getHttpFields().add("User-Agent","test");
|
||||
|
||||
HttpGenerator.Result
|
||||
result=gen.generate(null,null,null,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,null,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.State.COMMITTING_COMPLETING,gen.getState());
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertTrue(!gen.isChunking());
|
||||
|
||||
result=gen.generate(header,null,null,null,null);
|
||||
result=gen.generate(info,header,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertTrue(!gen.isChunking());
|
||||
String head = BufferUtil.toString(header);
|
||||
BufferUtil.clear(header);
|
||||
|
||||
result=gen.generate(null,null,null,null,null);
|
||||
result=gen.generate(info,null,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertTrue(!gen.isChunking());
|
||||
|
@ -122,34 +122,34 @@ public class HttpGeneratorClientTest
|
|||
ByteBuffer content=BufferUtil.toBuffer("Hello World");
|
||||
ByteBuffer content1=BufferUtil.toBuffer(". The quick brown fox jumped over the lazy dog.");
|
||||
Info info = new Info("POST","/index.html");
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
info.getHttpFields().add("Host","something");
|
||||
info.getHttpFields().add("User-Agent","test");
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content,null);
|
||||
result=gen.generate(info,null,null,null,content,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_BUFFER,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,buffer,content,null);
|
||||
result=gen.generate(info,null,null,buffer,content,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World",BufferUtil.toString(buffer));
|
||||
assertTrue(BufferUtil.isEmpty(content));
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World. The quick brown fox jumped over the lazy dog.",BufferUtil.toString(buffer));
|
||||
assertTrue(BufferUtil.isEmpty(content1));
|
||||
|
||||
result=gen.generate(null,null,buffer,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,buffer,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING_COMPLETING,gen.getState());
|
||||
|
||||
result=gen.generate(header,null,buffer,null,null);
|
||||
result=gen.generate(info,header,null,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING,gen.getState());
|
||||
|
||||
|
@ -158,7 +158,7 @@ public class HttpGeneratorClientTest
|
|||
body += BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,null,null);
|
||||
result=gen.generate(info,null,null,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -181,30 +181,30 @@ public class HttpGeneratorClientTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info = new Info("POST","/index.html");
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
info.getHttpFields().add("Host","something");
|
||||
info.getHttpFields().add("User-Agent","test");
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_BUFFER,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,buffer,content0,null);
|
||||
result=gen.generate(info,null,null,buffer,content0,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World! ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content0.remaining());
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
assertEquals(43,content1.remaining());
|
||||
|
||||
result=gen.generate(header,null,buffer,content1,null);
|
||||
result=gen.generate(info,header,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
|
@ -216,12 +216,12 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_CHUNK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
ByteBuffer chunk=BufferUtil.allocate(HttpGenerator.CHUNK_SIZE);
|
||||
result=gen.generate(null,chunk,buffer,content1,null);
|
||||
result=gen.generate(info,null,chunk,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("\r\n10\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -231,7 +231,7 @@ public class HttpGeneratorClientTest
|
|||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,content1,null);
|
||||
result=gen.generate(info,null,chunk,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("\r\n10\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -241,14 +241,14 @@ public class HttpGeneratorClientTest
|
|||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,content1,null);
|
||||
result=gen.generate(info,null,chunk,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("",BufferUtil.toString(chunk));
|
||||
assertEquals(" lazy dog. ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content1.remaining());
|
||||
|
||||
result=gen.generate(null,chunk,buffer,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,chunk,buffer,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING,gen.getState());
|
||||
assertEquals("\r\nB\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -257,7 +257,7 @@ public class HttpGeneratorClientTest
|
|||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,null,null);
|
||||
result=gen.generate(info,null,chunk,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals("\r\n0\r\n\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -265,7 +265,7 @@ public class HttpGeneratorClientTest
|
|||
BufferUtil.toString(chunk);
|
||||
BufferUtil.clear(chunk);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,null,null);
|
||||
result=gen.generate(info,null,chunk,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -289,7 +289,7 @@ public class HttpGeneratorClientTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello Cruel World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info = new Info("POST","/index.html");
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
gen.setLargeContent(8);
|
||||
|
||||
info.getHttpFields().add("Host","something");
|
||||
|
@ -297,11 +297,11 @@ public class HttpGeneratorClientTest
|
|||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
|
||||
result=gen.generate(header,null,null,content0,null);
|
||||
result=gen.generate(info,header,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertTrue(gen.isChunking());
|
||||
|
@ -311,16 +311,16 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(content0);
|
||||
BufferUtil.clear(content0);
|
||||
|
||||
result=gen.generate(header,null,null,content0,null);
|
||||
result=gen.generate(info,header,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,null,content1,null);
|
||||
result=gen.generate(info,null,null,null,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_CHUNK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
ByteBuffer chunk=BufferUtil.allocate(HttpGenerator.CHUNK_SIZE);
|
||||
result=gen.generate(null,chunk,null,content1,null);
|
||||
result=gen.generate(info,null,chunk,null,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("\r\n2E\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -328,13 +328,13 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(chunk)+BufferUtil.toString(content1);
|
||||
BufferUtil.clear(content1);
|
||||
|
||||
result=gen.generate(null,chunk,null,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,chunk,null,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals("\r\n0\r\n\r\n",BufferUtil.toString(chunk));
|
||||
BufferUtil.toString(chunk);
|
||||
|
||||
result=gen.generate(null,chunk,null,null,null);
|
||||
result=gen.generate(info,null,chunk,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -360,7 +360,7 @@ public class HttpGeneratorClientTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info = new Info("POST","/index.html");
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
info.getHttpFields().add("Host","something");
|
||||
info.getHttpFields().add("User-Agent","test");
|
||||
|
@ -369,23 +369,23 @@ public class HttpGeneratorClientTest
|
|||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_BUFFER,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,buffer,content0,null);
|
||||
result=gen.generate(info,null,null,buffer,content0,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World! ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content0.remaining());
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
assertEquals(43,content1.remaining());
|
||||
|
||||
result=gen.generate(header,null,buffer,content1,null);
|
||||
result=gen.generate(info,header,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
|
@ -397,7 +397,7 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals(" quick brown fox",BufferUtil.toString(buffer));
|
||||
|
@ -405,7 +405,7 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals(" jumped over the",BufferUtil.toString(buffer));
|
||||
|
@ -413,20 +413,20 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals(" lazy dog. ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content1.remaining());
|
||||
|
||||
result=gen.generate(null,null,buffer,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,buffer,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING,gen.getState());
|
||||
assertEquals(" lazy dog. ",BufferUtil.toString(buffer));
|
||||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,null,null);
|
||||
result=gen.generate(info,null,null,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals(0,buffer.remaining());
|
||||
|
@ -451,7 +451,7 @@ public class HttpGeneratorClientTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info = new Info("POST","/index.html");
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
gen.setLargeContent(8);
|
||||
|
||||
info.getHttpFields().add("Host","something");
|
||||
|
@ -461,11 +461,11 @@ public class HttpGeneratorClientTest
|
|||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
|
||||
result=gen.generate(header,null,null,content0,null);
|
||||
result=gen.generate(info,header,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertTrue(!gen.isChunking());
|
||||
|
@ -475,17 +475,17 @@ public class HttpGeneratorClientTest
|
|||
body+=BufferUtil.toString(content0);
|
||||
BufferUtil.clear(content0);
|
||||
|
||||
result=gen.generate(header,null,null,null,null);
|
||||
result=gen.generate(info,header,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,null,content1,null);
|
||||
result=gen.generate(info,null,null,null,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
body+=BufferUtil.toString(content1);
|
||||
BufferUtil.clear(content1);
|
||||
|
||||
result=gen.generate(null,null,null,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,null,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.junit.Test;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class HttpGeneratorTest
|
||||
public class HttpGeneratorServerTest
|
||||
{
|
||||
private class Handler implements HttpParser.ResponseHandler
|
||||
{
|
||||
|
@ -230,7 +230,7 @@ public class HttpGeneratorTest
|
|||
return _reason;
|
||||
}
|
||||
|
||||
private String build(int version,HttpGenerator gen,String reason, String connection, String te, int chunks) throws Exception
|
||||
private String build(HttpGenerator.Info info, int version,HttpGenerator gen,String reason, String connection, String te, int chunks) throws Exception
|
||||
{
|
||||
String response="";
|
||||
_connection=connection;
|
||||
|
@ -283,7 +283,7 @@ public class HttpGeneratorTest
|
|||
BufferUtil.toSummaryString(buffer),
|
||||
BufferUtil.toSummaryString(content),
|
||||
action,gen.getState());*/
|
||||
HttpGenerator.Result result=gen.generate(header,chunk,buffer,content,action);
|
||||
HttpGenerator.Result result=gen.generate(info,header,chunk,buffer,content,action);
|
||||
/*System.err.printf("%s (%s,%s,%s,%s,%s)@%s%n",
|
||||
result,
|
||||
BufferUtil.toSummaryString(header),
|
||||
|
@ -405,7 +405,7 @@ public class HttpGeneratorTest
|
|||
// For each test result
|
||||
for (int r=0;r<tr.length;r++)
|
||||
{
|
||||
HttpGenerator gen = new HttpGenerator(tr[r]);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
// chunks = 1 to 3
|
||||
for (int chunks=1;chunks<=6;chunks++)
|
||||
|
@ -419,7 +419,7 @@ public class HttpGeneratorTest
|
|||
gen.reset();
|
||||
tr[r].getHttpFields().clear();
|
||||
|
||||
String response=tr[r].build(v,gen,"OK\r\nTest",connect[c],null,chunks);
|
||||
String response=tr[r].build(tr[r],v,gen,"OK\r\nTest",connect[c],null,chunks);
|
||||
|
||||
// System.err.println("===\n"+t+"\n"+response+(gen.isPersistent()?"...\n":"---\n"));
|
||||
|
||||
|
@ -472,21 +472,21 @@ public class HttpGeneratorTest
|
|||
ByteBuffer header=BufferUtil.allocate(8096);
|
||||
|
||||
Info info=new Info(200);
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
info.getHttpFields().add("Last-Modified",HttpFields.__01Jan1970);
|
||||
|
||||
HttpGenerator.Result
|
||||
result=gen.generate(null,null,null,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,null,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.State.COMMITTING_COMPLETING,gen.getState());
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
|
||||
result=gen.generate(header,null,null,null,null);
|
||||
result=gen.generate(info,header,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
String head = BufferUtil.toString(header);
|
||||
BufferUtil.clear(header);
|
||||
|
||||
result=gen.generate(null,null,null,null,null);
|
||||
result=gen.generate(info,null,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -505,28 +505,28 @@ public class HttpGeneratorTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info=new Info(200);
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
info.getHttpFields().add("Last-Modified",HttpFields.__01Jan1970);
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_BUFFER,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,buffer,content0,null);
|
||||
result=gen.generate(info,null,null,buffer,content0,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World! ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content0.remaining());
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
assertEquals(43,content1.remaining());
|
||||
|
||||
result=gen.generate(header,null,buffer,content1,null);
|
||||
result=gen.generate(info,header,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
|
@ -538,12 +538,12 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_CHUNK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
ByteBuffer chunk=BufferUtil.allocate(HttpGenerator.CHUNK_SIZE);
|
||||
result=gen.generate(null,chunk,buffer,content1,null);
|
||||
result=gen.generate(info,null,chunk,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("\r\n10\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -553,7 +553,7 @@ public class HttpGeneratorTest
|
|||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,content1,null);
|
||||
result=gen.generate(info,null,chunk,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("\r\n10\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -563,14 +563,14 @@ public class HttpGeneratorTest
|
|||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,content1,null);
|
||||
result=gen.generate(info,null,chunk,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("",BufferUtil.toString(chunk));
|
||||
assertEquals(" lazy dog. ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content1.remaining());
|
||||
|
||||
result=gen.generate(null,chunk,buffer,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,chunk,buffer,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING,gen.getState());
|
||||
assertEquals("\r\nB\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -579,7 +579,7 @@ public class HttpGeneratorTest
|
|||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,null,null);
|
||||
result=gen.generate(info,null,chunk,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals("\r\n0\r\n\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -587,7 +587,7 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(chunk);
|
||||
BufferUtil.clear(chunk);
|
||||
|
||||
result=gen.generate(null,chunk,buffer,null,null);
|
||||
result=gen.generate(info,null,chunk,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -610,30 +610,30 @@ public class HttpGeneratorTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info=new Info(200);
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
info.getHttpFields().add("Last-Modified",HttpFields.__01Jan1970);
|
||||
info.getHttpFields().add("Content-Length","59");
|
||||
info.setContentLength(59);
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_BUFFER,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,buffer,content0,null);
|
||||
result=gen.generate(info,null,null,buffer,content0,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World! ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content0.remaining());
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
assertEquals(43,content1.remaining());
|
||||
|
||||
result=gen.generate(header,null,buffer,content1,null);
|
||||
result=gen.generate(info,header,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("Hello World! The",BufferUtil.toString(buffer));
|
||||
|
@ -645,7 +645,7 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals(" quick brown fox",BufferUtil.toString(buffer));
|
||||
|
@ -653,7 +653,7 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals(" jumped over the",BufferUtil.toString(buffer));
|
||||
|
@ -661,20 +661,20 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals(" lazy dog. ",BufferUtil.toString(buffer));
|
||||
assertEquals(0,content1.remaining());
|
||||
|
||||
result=gen.generate(null,null,buffer,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,buffer,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING,gen.getState());
|
||||
assertEquals(" lazy dog. ",BufferUtil.toString(buffer));
|
||||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,null,null);
|
||||
result=gen.generate(info,null,null,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals(0,buffer.remaining());
|
||||
|
@ -697,7 +697,7 @@ public class HttpGeneratorTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info=new Info(200);
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
gen.setLargeContent(8);
|
||||
|
||||
info.getHttpFields().add("Last-Modified",HttpFields.__01Jan1970);
|
||||
|
@ -706,11 +706,11 @@ public class HttpGeneratorTest
|
|||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
|
||||
result=gen.generate(header,null,null,content0,null);
|
||||
result=gen.generate(info,header,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertTrue(!gen.isChunking());
|
||||
|
@ -720,17 +720,17 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(content0);
|
||||
BufferUtil.clear(content0);
|
||||
|
||||
result=gen.generate(header,null,null,null,null);
|
||||
result=gen.generate(info,header,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,null,content1,null);
|
||||
result=gen.generate(info,null,null,null,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
body+=BufferUtil.toString(content1);
|
||||
BufferUtil.clear(content1);
|
||||
|
||||
result=gen.generate(null,null,null,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,null,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -752,18 +752,18 @@ public class HttpGeneratorTest
|
|||
ByteBuffer content0=BufferUtil.toBuffer("Hello Cruel World! ");
|
||||
ByteBuffer content1=BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
Info info=new Info(200);
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
gen.setLargeContent(8);
|
||||
|
||||
info.getHttpFields().add("Last-Modified",HttpFields.__01Jan1970);
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content0,null);
|
||||
result=gen.generate(info,null,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING,gen.getState());
|
||||
|
||||
result=gen.generate(header,null,null,content0,null);
|
||||
result=gen.generate(info,header,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertTrue(gen.isChunking());
|
||||
|
@ -773,16 +773,16 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(content0);
|
||||
BufferUtil.clear(content0);
|
||||
|
||||
result=gen.generate(header,null,null,content0,null);
|
||||
result=gen.generate(info,header,null,null,content0,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,null,content1,null);
|
||||
result=gen.generate(info,null,null,null,content1,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_CHUNK,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
|
||||
ByteBuffer chunk=BufferUtil.allocate(HttpGenerator.CHUNK_SIZE);
|
||||
result=gen.generate(null,chunk,null,content1,null);
|
||||
result=gen.generate(info,null,chunk,null,content1,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH_CONTENT,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTED,gen.getState());
|
||||
assertEquals("\r\n2E\r\n",BufferUtil.toString(chunk));
|
||||
|
@ -790,13 +790,13 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(chunk)+BufferUtil.toString(content1);
|
||||
BufferUtil.clear(content1);
|
||||
|
||||
result=gen.generate(null,chunk,null,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,chunk,null,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals("\r\n0\r\n\r\n",BufferUtil.toString(chunk));
|
||||
body+=BufferUtil.toString(chunk);
|
||||
|
||||
result=gen.generate(null,chunk,null,null,null);
|
||||
result=gen.generate(info,null,chunk,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
|
@ -820,32 +820,32 @@ public class HttpGeneratorTest
|
|||
ByteBuffer content=BufferUtil.toBuffer("Hello World");
|
||||
ByteBuffer content1=BufferUtil.toBuffer(". The quick brown fox jumped over the lazy dog.");
|
||||
Info info=new Info(200);
|
||||
HttpGenerator gen = new HttpGenerator(info);
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
info.getHttpFields().add("Last-Modified",HttpFields.__01Jan1970);
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result=gen.generate(null,null,null,content,null);
|
||||
result=gen.generate(info,null,null,null,content,null);
|
||||
assertEquals(HttpGenerator.Result.NEED_BUFFER,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
|
||||
result=gen.generate(null,null,buffer,content,null);
|
||||
result=gen.generate(info,null,null,buffer,content,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World",BufferUtil.toString(buffer));
|
||||
assertTrue(BufferUtil.isEmpty(content));
|
||||
|
||||
result=gen.generate(null,null,buffer,content1,null);
|
||||
result=gen.generate(info,null,null,buffer,content1,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.START,gen.getState());
|
||||
assertEquals("Hello World. The quick brown fox jumped over the lazy dog.",BufferUtil.toString(buffer));
|
||||
assertTrue(BufferUtil.isEmpty(content1));
|
||||
|
||||
result=gen.generate(null,null,buffer,null,Action.COMPLETE);
|
||||
result=gen.generate(info,null,null,buffer,null,Action.COMPLETE);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER,result);
|
||||
assertEquals(HttpGenerator.State.COMMITTING_COMPLETING,gen.getState());
|
||||
|
||||
result=gen.generate(header,null,buffer,null,null);
|
||||
result=gen.generate(info,header,null,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING,gen.getState());
|
||||
|
||||
|
@ -854,7 +854,7 @@ public class HttpGeneratorTest
|
|||
body+=BufferUtil.toString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
|
||||
result=gen.generate(null,null,buffer,null,null);
|
||||
result=gen.generate(info,null,null,buffer,null,null);
|
||||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
|
@ -74,7 +74,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
};
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected HttpProcessor _connection;
|
||||
protected HttpChannel _connection;
|
||||
private List<AsyncListener> _lastAsyncListeners;
|
||||
private List<AsyncListener> _asyncListeners;
|
||||
private List<ContinuationListener> _continuationListeners;
|
||||
|
@ -98,7 +98,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void setConnection(final HttpProcessor connection)
|
||||
protected void setConnection(final HttpChannel connection)
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
|
|
|
@ -53,27 +53,26 @@ import org.eclipse.jetty.util.thread.Timeout.Task;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class HttpProcessor
|
||||
public abstract class HttpChannel
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(HttpProcessor.class);
|
||||
private static final Logger LOG = Log.getLogger(HttpChannel.class);
|
||||
|
||||
private static final ThreadLocal<HttpProcessor> __currentChannel = new ThreadLocal<HttpProcessor>();
|
||||
private static final ThreadLocal<HttpChannel> __currentChannel = new ThreadLocal<HttpChannel>();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static HttpProcessor getCurrentHttpChannel()
|
||||
public static HttpChannel getCurrentHttpChannel()
|
||||
{
|
||||
return __currentChannel.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected static void setCurrentHttpChannel(HttpProcessor channel)
|
||||
protected static void setCurrentHttpChannel(HttpChannel channel)
|
||||
{
|
||||
__currentChannel.set(channel);
|
||||
}
|
||||
|
||||
private int _requests;
|
||||
|
||||
private final HttpController _controller;
|
||||
private final Server _server;
|
||||
private final HttpURI _uri;
|
||||
|
||||
|
@ -156,10 +155,9 @@ public abstract class HttpProcessor
|
|||
/** Constructor
|
||||
*
|
||||
*/
|
||||
public HttpProcessor(Server server, HttpController controller)
|
||||
public HttpChannel(Server server)
|
||||
{
|
||||
_server = server;
|
||||
_controller=controller;
|
||||
_uri = new HttpURI(URIUtil.__CHARSET);
|
||||
_requestFields = new HttpFields();
|
||||
_responseFields = new HttpFields(server.getMaxCookieVersion());
|
||||
|
@ -187,12 +185,6 @@ public abstract class HttpProcessor
|
|||
{
|
||||
return _server;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpController getHttpTransport()
|
||||
{
|
||||
return _controller;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public AsyncContinuation getAsyncContinuation()
|
||||
|
@ -255,16 +247,16 @@ public abstract class HttpProcessor
|
|||
// is content missing?
|
||||
if (available()==0)
|
||||
{
|
||||
if (_controller.isResponseCommitted())
|
||||
if (isResponseCommitted())
|
||||
throw new IllegalStateException("Committed before 100 Continues");
|
||||
|
||||
_controller.send1xx(HttpStatus.CONTINUE_100);
|
||||
send1xx(HttpStatus.CONTINUE_100);
|
||||
}
|
||||
_expect100Continue=false;
|
||||
}
|
||||
|
||||
if (_in == null)
|
||||
_in = new HttpInput(HttpProcessor.this);
|
||||
_in = new HttpInput(HttpChannel.this);
|
||||
return _in;
|
||||
}
|
||||
|
||||
|
@ -377,7 +369,7 @@ public abstract class HttpProcessor
|
|||
if (_async.isInitial())
|
||||
{
|
||||
_request.setDispatcherType(DispatcherType.REQUEST);
|
||||
_controller.customize(_request);
|
||||
customize(_request);
|
||||
server.handle(this);
|
||||
}
|
||||
else
|
||||
|
@ -417,7 +409,7 @@ public abstract class HttpProcessor
|
|||
LOG.warn(String.valueOf(_uri),e);
|
||||
error=true;
|
||||
_request.setHandled(true);
|
||||
_controller.sendError(info==null?400:500, null, null, true);
|
||||
sendError(info==null?400:500, null, null, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -443,17 +435,17 @@ public abstract class HttpProcessor
|
|||
// do anything special here other than make the connection not persistent
|
||||
_expect100Continue = false;
|
||||
if (!_response.isCommitted())
|
||||
_controller.setPersistent(false);
|
||||
setPersistent(false);
|
||||
}
|
||||
|
||||
if (error)
|
||||
_controller.setPersistent(false);
|
||||
setPersistent(false);
|
||||
else if (!_response.isCommitted() && !_request.isHandled())
|
||||
_response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
|
||||
_response.complete();
|
||||
if (_controller.isPersistent())
|
||||
_controller.persist();
|
||||
if (isPersistent())
|
||||
persist();
|
||||
|
||||
_request.setHandled(true);
|
||||
}
|
||||
|
@ -551,6 +543,12 @@ public abstract class HttpProcessor
|
|||
throw new SocketTimeoutException(">"+getMaxIdleTime()+"ms");
|
||||
try
|
||||
{
|
||||
// Alternate approach would be to
|
||||
// blockReadable
|
||||
// read and then runParser
|
||||
// runParser
|
||||
// This would be better for a client
|
||||
|
||||
setReadInterested(true);
|
||||
_inputQ.wait(timeout);
|
||||
}
|
||||
|
@ -714,7 +712,7 @@ public abstract class HttpProcessor
|
|||
case HTTP_0_9:
|
||||
break;
|
||||
case HTTP_1_0:
|
||||
if (_controller.isPersistent())
|
||||
if (isPersistent())
|
||||
{
|
||||
_responseFields.add(HttpHeader.CONNECTION,HttpHeaderValue.KEEP_ALIVE);
|
||||
}
|
||||
|
@ -725,7 +723,7 @@ public abstract class HttpProcessor
|
|||
|
||||
case HTTP_1_1:
|
||||
|
||||
if (!_controller.isPersistent())
|
||||
if (!isPersistent())
|
||||
{
|
||||
_responseFields.add(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
|
||||
}
|
||||
|
@ -736,7 +734,7 @@ public abstract class HttpProcessor
|
|||
{
|
||||
LOG.debug("!host {}",this);
|
||||
_responseFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE);
|
||||
_controller.sendError(HttpStatus.BAD_REQUEST_400,null,null,true);
|
||||
sendError(HttpStatus.BAD_REQUEST_400,null,null,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -744,7 +742,7 @@ public abstract class HttpProcessor
|
|||
{
|
||||
LOG.debug("!expectation {}",this);
|
||||
_responseFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE);
|
||||
_controller.sendError(HttpStatus.EXPECTATION_FAILED_417,null,null,true);
|
||||
sendError(HttpStatus.EXPECTATION_FAILED_417,null,null,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -797,7 +795,7 @@ public abstract class HttpProcessor
|
|||
{
|
||||
Output()
|
||||
{
|
||||
super(_controller,HttpProcessor.this);
|
||||
super(HttpChannel.this);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -875,22 +873,40 @@ public abstract class HttpProcessor
|
|||
|
||||
|
||||
|
||||
public void asyncDispatch()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void scheduleTimeout(Task timeout, long timeoutMs)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void cancelTimeout(Task timeout)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public abstract void asyncDispatch();
|
||||
|
||||
public abstract void scheduleTimeout(Task timeout, long timeoutMs);
|
||||
|
||||
public abstract void cancelTimeout(Task timeout);
|
||||
|
||||
|
||||
protected abstract int write(ByteBuffer content,boolean volatileContent) throws IOException;
|
||||
|
||||
protected abstract void sendError(int status, String reason, String content, boolean close) throws IOException;
|
||||
|
||||
protected abstract void send1xx(int processing102);
|
||||
|
||||
protected abstract int getContentBufferSize();
|
||||
|
||||
protected abstract void increaseContentBufferSize(int size);
|
||||
|
||||
protected abstract void resetBuffer();
|
||||
|
||||
protected abstract boolean isResponseCommitted();
|
||||
|
||||
protected abstract boolean isPersistent();
|
||||
|
||||
protected abstract void setPersistent(boolean persistent);
|
||||
|
||||
protected abstract void flushResponse() throws IOException;
|
||||
|
||||
protected abstract void completeResponse();
|
||||
|
||||
protected abstract Connector getConnector();
|
||||
|
||||
protected abstract void persist();
|
||||
|
||||
protected abstract void customize(Request request);
|
||||
|
||||
protected abstract void setReadInterested(boolean interested);
|
||||
}
|
|
@ -23,7 +23,9 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.eclipse.jetty.http.HttpException;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpGenerator;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.HttpGenerator.Action;
|
||||
import org.eclipse.jetty.http.HttpParser;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
|
@ -35,6 +37,7 @@ import org.eclipse.jetty.io.SelectableEndPoint;
|
|||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.Timeout.Task;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -49,7 +52,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
private final Connector _connector;
|
||||
private final HttpParser _parser;
|
||||
private final HttpGenerator _generator;
|
||||
private final HttpProcessor _processor;
|
||||
private final HttpChannel _channel;
|
||||
|
||||
int _toFlush;
|
||||
ByteBuffer _requestBuffer=null;
|
||||
|
@ -81,10 +84,10 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
_connector = connector;
|
||||
_server = server;
|
||||
|
||||
_processor = new HttpOverHttpProcessor(server,_controller);
|
||||
_channel = new HttpOverHttpChannel(server);
|
||||
|
||||
_parser = new HttpParser(_processor.getRequestHandler());
|
||||
_generator = new HttpGenerator(_processor.getResponseInfo());
|
||||
_parser = new HttpParser(_channel.getRequestHandler());
|
||||
_generator = new HttpGenerator();
|
||||
|
||||
}
|
||||
|
||||
|
@ -117,9 +120,9 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
/**
|
||||
* @return Returns the HttpChannel.
|
||||
*/
|
||||
public HttpProcessor getHttpChannel()
|
||||
public HttpChannel getHttpChannel()
|
||||
{
|
||||
return _processor;
|
||||
return _channel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -127,7 +130,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
{
|
||||
_parser.reset();
|
||||
_generator.reset();
|
||||
_processor.reset();
|
||||
_channel.reset();
|
||||
if (_requestBuffer!=null)
|
||||
_connector.getResponseBuffers().returnBuffer(_requestBuffer);
|
||||
_requestBuffer=null;
|
||||
|
@ -156,12 +159,6 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
return _parser.isIdle() && _generator.isIdle();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isReadInterested()
|
||||
{
|
||||
return !_processor.getAsyncContinuation().isSuspended() && !_parser.isComplete();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int getMaxIdleTime()
|
||||
|
@ -197,7 +194,6 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
// don't check for idle while dispatched (unless blocking IO is done).
|
||||
getSelectableEndPoint().setCheckForIdle(false);
|
||||
|
||||
|
||||
// While progress and the connection has not changed
|
||||
while (progress && connection==this)
|
||||
{
|
||||
|
@ -212,13 +208,13 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
|
||||
// If we parse to an event, call the connection
|
||||
if (BufferUtil.hasContent(_requestBuffer) && _parser.parseNext(_requestBuffer))
|
||||
_processor.handleRequest();
|
||||
_channel.handleRequest();
|
||||
|
||||
}
|
||||
catch (HttpException e)
|
||||
{
|
||||
progress=true;
|
||||
_controller.sendError(e.getStatus(), e.getReason(), null, true);
|
||||
_channel.sendError(e.getStatus(), e.getReason(), null, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -233,9 +229,9 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
if (_parser.isComplete() && _generator.isComplete())
|
||||
{
|
||||
// look for a switched connection instance?
|
||||
if (_processor.getResponse().getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
|
||||
if (_channel.getResponse().getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
|
||||
{
|
||||
Connection switched=(Connection)_processor.getRequest().getAttribute("org.eclipse.jetty.io.Connection");
|
||||
Connection switched=(Connection)_channel.getRequest().getAttribute("org.eclipse.jetty.io.Connection");
|
||||
if (switched!=null)
|
||||
connection=switched;
|
||||
}
|
||||
|
@ -244,7 +240,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
reset();
|
||||
progress=true;
|
||||
}
|
||||
else if (_processor.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
else if (_channel.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
{
|
||||
// The request is suspended, so even though progress has been made,
|
||||
// exit the while loop by setting progress to false
|
||||
|
@ -263,7 +259,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
setCurrentConnection(null);
|
||||
|
||||
// If we are not suspended
|
||||
if (!_processor.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
if (!_channel.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
{
|
||||
// reenable idle checking unless request is suspended
|
||||
getSelectableEndPoint().setCheckForIdle(true);
|
||||
|
@ -294,7 +290,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
BufferUtil.toSummaryString(content),
|
||||
action,_generator.getState());
|
||||
|
||||
HttpGenerator.Result result=_generator.generate(_responseHeader,_chunk,_responseBuffer,content,action);
|
||||
HttpGenerator.Result result=_generator.generate(_channel.getResponseInfo(),_responseHeader,_chunk,_responseBuffer,content,action);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{}: {} ({},{},{},{},{})@{}",
|
||||
this,
|
||||
|
@ -313,7 +309,6 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
|
||||
case NEED_BUFFER:
|
||||
_responseBuffer=_connector.getResponseBuffers().getBuffer();
|
||||
_responseBuffer=BufferUtil.allocate(8192);
|
||||
break;
|
||||
|
||||
case NEED_CHUNK:
|
||||
|
@ -414,7 +409,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
_processor.onClose();
|
||||
_channel.onClose();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -422,7 +417,7 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
public void onInputShutdown() throws IOException
|
||||
{
|
||||
// If we don't have a committed response and we are not suspended
|
||||
if (_generator.isIdle() && !_processor.getRequest().getAsyncContinuation().isSuspended())
|
||||
if (_generator.isIdle() && !_channel.getRequest().getAsyncContinuation().isSuspended())
|
||||
{
|
||||
// then no more can happen, so close.
|
||||
_endp.close();
|
||||
|
@ -436,11 +431,11 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private final class HttpOverHttpProcessor extends HttpProcessor
|
||||
private class HttpOverHttpChannel extends HttpChannel
|
||||
{
|
||||
private HttpOverHttpProcessor(Server server, HttpController controller)
|
||||
private HttpOverHttpChannel(Server server)
|
||||
{
|
||||
super(server,controller);
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -460,75 +455,136 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
{
|
||||
return HttpConnection.this.getMaxIdleTime();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private final HttpController _controller = new HttpController()
|
||||
{
|
||||
@Override
|
||||
public void asyncDispatch()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleTimeout(Task timeout, long timeoutMs)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTimeout(Task timeout)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int write(ByteBuffer content, boolean volatileContent) throws IOException
|
||||
protected int write(ByteBuffer content, boolean volatileContent) throws IOException
|
||||
{
|
||||
return HttpConnection.this.generate(content,Action.PREPARE,volatileContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPersistent(boolean persistent)
|
||||
protected void setPersistent(boolean persistent)
|
||||
{
|
||||
_parser.setPersistent(persistent);
|
||||
_generator.setPersistent(persistent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int status, String reason, String content, boolean close) throws IOException
|
||||
protected void sendError(final int status, final String reason, String content, boolean close) throws IOException
|
||||
{
|
||||
if (_generator.isCommitted())
|
||||
throw new IllegalStateException("Committed");
|
||||
|
||||
HttpGenerator.ResponseInfo response =new HttpGenerator.ResponseInfo()
|
||||
{
|
||||
@Override
|
||||
public HttpVersion getHttpVersion()
|
||||
{
|
||||
return HttpVersion.HTTP_1_1;
|
||||
}
|
||||
@Override
|
||||
public HttpFields getHttpFields()
|
||||
{
|
||||
return getResponseFields();
|
||||
}
|
||||
@Override
|
||||
public long getContentLength()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public boolean isHead()
|
||||
{
|
||||
return getRequest().isHead();
|
||||
}
|
||||
@Override
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
@Override
|
||||
public String getReason()
|
||||
{
|
||||
return reason;
|
||||
}
|
||||
};
|
||||
|
||||
if (close)
|
||||
_generator.setPersistent(false);
|
||||
|
||||
ByteBuffer buf=BufferUtil.toBuffer(content);
|
||||
|
||||
if (_responseHeader==null)
|
||||
_responseHeader=_connector.getResponseBuffers().getHeader();
|
||||
if (_responseBuffer==null)
|
||||
_responseBuffer=_connector.getResponseBuffers().getBuffer();
|
||||
|
||||
_generator.generate(response,_responseHeader,null,_responseBuffer,buf,Action.COMPLETE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void send1xx(int processing102)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send1xx(int processing102)
|
||||
protected void resetBuffer()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBuffer()
|
||||
protected void persist()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResponseCommitted()
|
||||
protected boolean isResponseCommitted()
|
||||
{
|
||||
return _generator.isCommitted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPersistent()
|
||||
protected boolean isPersistent()
|
||||
{
|
||||
return _generator.isPersistent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increaseContentBufferSize(int size)
|
||||
protected void increaseContentBufferSize(int size)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentBufferSize()
|
||||
protected int getContentBufferSize()
|
||||
{
|
||||
ByteBuffer buffer=_responseBuffer;
|
||||
if (buffer!=null)
|
||||
|
@ -538,29 +594,35 @@ public abstract class HttpConnection extends SelectableConnection
|
|||
}
|
||||
|
||||
@Override
|
||||
public Connector getConnector()
|
||||
protected Connector getConnector()
|
||||
{
|
||||
return _connector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushResponse() throws IOException
|
||||
protected void flushResponse() throws IOException
|
||||
{
|
||||
HttpConnection.this.generate(null,Action.FLUSH,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(Request request)
|
||||
protected void customize(Request request)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeResponse()
|
||||
protected void completeResponse()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setReadInterested(boolean interested)
|
||||
{
|
||||
_endp.setReadInterested(interested);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public interface HttpController
|
||||
{
|
||||
public int write(ByteBuffer content,boolean volatileContent) throws IOException;
|
||||
|
||||
void sendError(int status, String reason, String content, boolean close) throws IOException;
|
||||
|
||||
void send1xx(int processing102);
|
||||
|
||||
int getContentBufferSize();
|
||||
|
||||
void increaseContentBufferSize(int size);
|
||||
|
||||
void resetBuffer();
|
||||
|
||||
public boolean isResponseCommitted();
|
||||
|
||||
public boolean isPersistent();
|
||||
|
||||
public void setPersistent(boolean persistent);
|
||||
|
||||
public void flushResponse() throws IOException;
|
||||
|
||||
public void completeResponse();
|
||||
|
||||
Connector getConnector();
|
||||
|
||||
void persist();
|
||||
|
||||
void customize(Request request);
|
||||
|
||||
}
|
|
@ -23,13 +23,13 @@ import org.eclipse.jetty.util.BufferUtil;
|
|||
|
||||
public class HttpInput extends ServletInputStream
|
||||
{
|
||||
protected final HttpProcessor _connection;
|
||||
protected final HttpChannel _channel;
|
||||
protected final byte[] _byte=new byte[1];
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpInput(HttpProcessor connection)
|
||||
public HttpInput(HttpChannel channel)
|
||||
{
|
||||
_connection=connection;
|
||||
_channel=channel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -39,7 +39,7 @@ public class HttpInput extends ServletInputStream
|
|||
@Override
|
||||
public int read() throws IOException
|
||||
{
|
||||
int len=_connection.read(_byte,0,1);
|
||||
int len=_channel.read(_byte,0,1);
|
||||
return len<0?len:_byte[0];
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,14 @@ public class HttpInput extends ServletInputStream
|
|||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException
|
||||
{
|
||||
return _connection.read(_byte,0,1);
|
||||
return _channel.read(_byte,0,1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int available() throws IOException
|
||||
{
|
||||
return _connection.available();
|
||||
return _channel.available();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,8 +32,7 @@ import org.eclipse.jetty.util.ByteArrayOutputStream2;
|
|||
*/
|
||||
public class HttpOutput extends ServletOutputStream
|
||||
{
|
||||
private final HttpController _controller;
|
||||
private final HttpProcessor _processor;
|
||||
private final HttpChannel _channel;
|
||||
private boolean _closed;
|
||||
|
||||
// These are held here for reuse by Writer
|
||||
|
@ -44,10 +43,9 @@ public class HttpOutput extends ServletOutputStream
|
|||
long _written;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpOutput(HttpController controller, HttpProcessor processor)
|
||||
public HttpOutput(HttpChannel channel)
|
||||
{
|
||||
_controller=controller;
|
||||
_processor=processor;
|
||||
_channel=channel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -77,7 +75,7 @@ public class HttpOutput extends ServletOutputStream
|
|||
public void close() throws IOException
|
||||
{
|
||||
if (!_closed)
|
||||
_controller.completeResponse();
|
||||
_channel.completeResponse();
|
||||
_closed=true;
|
||||
}
|
||||
|
||||
|
@ -97,7 +95,7 @@ public class HttpOutput extends ServletOutputStream
|
|||
@Override
|
||||
public void flush() throws IOException
|
||||
{
|
||||
_controller.flushResponse();
|
||||
_channel.flushResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -107,8 +105,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
if (_closed)
|
||||
throw new IOException("Closed");
|
||||
|
||||
_written+=_controller.write(ByteBuffer.wrap(b,off,len),true);
|
||||
_processor.getResponse().checkAllContentWritten(_written);
|
||||
_written+=_channel.write(ByteBuffer.wrap(b,off,len),true);
|
||||
_channel.getResponse().checkAllContentWritten(_written);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -121,8 +119,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
if (_closed)
|
||||
throw new IOException("Closed");
|
||||
|
||||
_written+=_controller.write(ByteBuffer.wrap(b),true);
|
||||
_processor.getResponse().checkAllContentWritten(_written);
|
||||
_written+=_channel.write(ByteBuffer.wrap(b),true);
|
||||
_channel.getResponse().checkAllContentWritten(_written);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -135,8 +133,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
if (_closed)
|
||||
throw new IOException("Closed");
|
||||
|
||||
_written+=_controller.write(ByteBuffer.wrap(new byte[]{(byte)b}),true);
|
||||
_processor.getResponse().checkAllContentWritten(_written);
|
||||
_written+=_channel.write(ByteBuffer.wrap(new byte[]{(byte)b}),true);
|
||||
_channel.getResponse().checkAllContentWritten(_written);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -117,8 +117,7 @@ public class Request implements HttpServletRequest
|
|||
private static final Collection<Locale> __defaultLocale = Collections.singleton(Locale.getDefault());
|
||||
private static final int __NONE = 0, _STREAM = 1, __READER = 2;
|
||||
|
||||
private final HttpProcessor _processor;
|
||||
private final HttpController _transport;
|
||||
private final HttpChannel _channel;
|
||||
private HttpFields _fields;
|
||||
private final AsyncContinuation _async = new AsyncContinuation();
|
||||
|
||||
|
@ -168,12 +167,11 @@ public class Request implements HttpServletRequest
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Request(HttpProcessor processor)
|
||||
public Request(HttpChannel channel)
|
||||
{
|
||||
_processor = processor;
|
||||
_transport = processor.getHttpTransport();
|
||||
_fields=_processor.getRequestFields();
|
||||
_async.setConnection(processor);
|
||||
_channel = channel;
|
||||
_fields=_channel.getRequestFields();
|
||||
_async.setConnection(channel);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -253,10 +251,10 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
else
|
||||
{
|
||||
Number size = (Number)_processor.getServer()
|
||||
Number size = (Number)_channel.getServer()
|
||||
.getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
|
||||
maxFormContentSize = size == null?200000:size.intValue();
|
||||
Number keys = (Number)_processor.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
|
||||
Number keys = (Number)_channel.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
|
||||
maxFormKeys = keys == null?1000:keys.intValue();
|
||||
}
|
||||
|
||||
|
@ -390,9 +388,9 @@ public class Request implements HttpServletRequest
|
|||
/**
|
||||
* @return Returns the connection.
|
||||
*/
|
||||
public HttpProcessor getConnection()
|
||||
public HttpChannel getConnection()
|
||||
{
|
||||
return _processor;
|
||||
return _channel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -523,7 +521,7 @@ public class Request implements HttpServletRequest
|
|||
if (_inputState != __NONE && _inputState != _STREAM)
|
||||
throw new IllegalStateException("READER");
|
||||
_inputState = _STREAM;
|
||||
return _processor.getInputStream();
|
||||
return _channel.getInputStream();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -622,7 +620,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public String getLocalAddr()
|
||||
{
|
||||
InetSocketAddress local=_processor.getLocalAddress();
|
||||
InetSocketAddress local=_channel.getLocalAddress();
|
||||
return local.getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
|
@ -632,7 +630,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public String getLocalName()
|
||||
{
|
||||
InetSocketAddress local=_processor.getLocalAddress();
|
||||
InetSocketAddress local=_channel.getLocalAddress();
|
||||
return local.getHostString();
|
||||
}
|
||||
|
||||
|
@ -642,7 +640,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public int getLocalPort()
|
||||
{
|
||||
InetSocketAddress local=_processor.getLocalAddress();
|
||||
InetSocketAddress local=_channel.getLocalAddress();
|
||||
return local.getPort();
|
||||
}
|
||||
|
||||
|
@ -824,7 +822,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
InetSocketAddress remote=_remote;
|
||||
if (remote==null)
|
||||
remote=_processor.getRemoteAddress();
|
||||
remote=_channel.getRemoteAddress();
|
||||
return remote==null?"":remote.getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
|
@ -836,7 +834,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
InetSocketAddress remote=_remote;
|
||||
if (remote==null)
|
||||
remote=_processor.getRemoteAddress();
|
||||
remote=_channel.getRemoteAddress();
|
||||
return remote==null?"":remote.getHostString();
|
||||
}
|
||||
|
||||
|
@ -848,7 +846,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
InetSocketAddress remote=_remote;
|
||||
if (remote==null)
|
||||
remote=_processor.getRemoteAddress();
|
||||
remote=_channel.getRemoteAddress();
|
||||
return remote==null?0:remote.getPort();
|
||||
}
|
||||
|
||||
|
@ -937,7 +935,7 @@ public class Request implements HttpServletRequest
|
|||
/* ------------------------------------------------------------ */
|
||||
public Response getResponse()
|
||||
{
|
||||
return _processor.getResponse();
|
||||
return _channel.getResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1019,8 +1017,8 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
try
|
||||
{
|
||||
if (_processor != null)
|
||||
_transport.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true);
|
||||
if (_channel != null)
|
||||
_channel.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true);
|
||||
}
|
||||
catch (IOException e1)
|
||||
{
|
||||
|
@ -1041,7 +1039,7 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
|
||||
// Return host from connection
|
||||
if (_processor != null)
|
||||
if (_channel != null)
|
||||
{
|
||||
_serverName = getLocalName();
|
||||
_port = getLocalPort();
|
||||
|
@ -1078,7 +1076,7 @@ public class Request implements HttpServletRequest
|
|||
_port = _uri.getPort();
|
||||
else
|
||||
{
|
||||
InetSocketAddress local = _processor.getLocalAddress();
|
||||
InetSocketAddress local = _channel.getLocalAddress();
|
||||
_port = local == null?0:local.getPort();
|
||||
}
|
||||
}
|
||||
|
@ -1123,7 +1121,7 @@ public class Request implements HttpServletRequest
|
|||
/* ------------------------------------------------------------ */
|
||||
public ServletResponse getServletResponse()
|
||||
{
|
||||
return _processor.getResponse();
|
||||
return _channel.getResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1158,7 +1156,7 @@ public class Request implements HttpServletRequest
|
|||
_session = _sessionManager.newHttpSession(this);
|
||||
HttpCookie cookie = _sessionManager.getSessionCookie(_session,getContextPath(),isSecure());
|
||||
if (cookie != null)
|
||||
_processor.getResponse().addCookie(cookie);
|
||||
_channel.getResponse().addCookie(cookie);
|
||||
|
||||
return _session;
|
||||
}
|
||||
|
@ -1313,7 +1311,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public boolean isSecure()
|
||||
{
|
||||
return _transport.getConnector().isConfidential(this);
|
||||
return _channel.getConnector().isConfidential(this);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1471,7 +1469,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
try
|
||||
{
|
||||
((HttpProcessor.Output)getServletResponse().getOutputStream()).sendContent(value);
|
||||
((HttpChannel.Output)getServletResponse().getOutputStream()).sendContent(value);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@ -1850,7 +1848,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
if (!_asyncSupported)
|
||||
throw new IllegalStateException("!asyncSupported");
|
||||
_async.suspend(_context,this,_processor.getResponse());
|
||||
_async.suspend(_context,this,_channel.getResponse());
|
||||
return _async;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,8 +65,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__";
|
||||
|
||||
private final HttpProcessor _processor;
|
||||
private final HttpController _controller;
|
||||
private final HttpChannel _channel;
|
||||
private final HttpFields _fields;
|
||||
private int _status=SC_OK;
|
||||
private String _reason;
|
||||
|
@ -84,10 +83,9 @@ public class Response implements HttpServletResponse
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public Response(HttpProcessor channel)
|
||||
public Response(HttpChannel channel)
|
||||
{
|
||||
_processor=channel;
|
||||
_controller=channel.getHttpTransport();
|
||||
_channel=channel;
|
||||
_fields=channel.getResponseFields();
|
||||
}
|
||||
|
||||
|
@ -164,7 +162,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public String encodeURL(String url)
|
||||
{
|
||||
final Request request=_processor.getRequest();
|
||||
final Request request=_channel.getRequest();
|
||||
SessionManager sessionManager = request.getSessionManager();
|
||||
if (sessionManager==null)
|
||||
return url;
|
||||
|
@ -285,7 +283,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void sendError(int code, String message) throws IOException
|
||||
{
|
||||
if (_processor.isIncluding())
|
||||
if (_channel.isIncluding())
|
||||
return;
|
||||
|
||||
if (isCommitted())
|
||||
|
@ -311,21 +309,21 @@ public class Response implements HttpServletResponse
|
|||
code!=SC_PARTIAL_CONTENT &&
|
||||
code>=SC_OK)
|
||||
{
|
||||
Request request = _processor.getRequest();
|
||||
Request request = _channel.getRequest();
|
||||
|
||||
ErrorHandler error_handler = null;
|
||||
ContextHandler.Context context = request.getContext();
|
||||
if (context!=null)
|
||||
error_handler=context.getContextHandler().getErrorHandler();
|
||||
if (error_handler==null)
|
||||
error_handler = _processor.getServer().getBean(ErrorHandler.class);
|
||||
error_handler = _channel.getServer().getBean(ErrorHandler.class);
|
||||
if (error_handler!=null)
|
||||
{
|
||||
request.setAttribute(Dispatcher.ERROR_STATUS_CODE,new Integer(code));
|
||||
request.setAttribute(Dispatcher.ERROR_MESSAGE, message);
|
||||
request.setAttribute(Dispatcher.ERROR_REQUEST_URI, request.getRequestURI());
|
||||
request.setAttribute(Dispatcher.ERROR_SERVLET_NAME,request.getServletName());
|
||||
error_handler.handle(null,_processor.getRequest(),_processor.getRequest(),this );
|
||||
error_handler.handle(null,_channel.getRequest(),_channel.getRequest(),this );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -374,8 +372,8 @@ public class Response implements HttpServletResponse
|
|||
}
|
||||
else if (code!=SC_PARTIAL_CONTENT)
|
||||
{
|
||||
_processor.getRequestFields().remove(HttpHeader.CONTENT_TYPE);
|
||||
_processor.getRequestFields().remove(HttpHeader.CONTENT_LENGTH);
|
||||
_channel.getRequestFields().remove(HttpHeader.CONTENT_TYPE);
|
||||
_channel.getRequestFields().remove(HttpHeader.CONTENT_LENGTH);
|
||||
_characterEncoding=null;
|
||||
_mimeType=null;
|
||||
}
|
||||
|
@ -405,8 +403,8 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void sendProcessing() throws IOException
|
||||
{
|
||||
if (_processor.isExpecting102Processing() && !isCommitted())
|
||||
_controller.send1xx(HttpStatus.PROCESSING_102);
|
||||
if (_channel.isExpecting102Processing() && !isCommitted())
|
||||
_channel.send1xx(HttpStatus.PROCESSING_102);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -415,7 +413,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void sendRedirect(String location) throws IOException
|
||||
{
|
||||
if (_processor.isIncluding())
|
||||
if (_channel.isIncluding())
|
||||
return;
|
||||
|
||||
if (location==null)
|
||||
|
@ -423,12 +421,12 @@ public class Response implements HttpServletResponse
|
|||
|
||||
if (!URIUtil.hasScheme(location))
|
||||
{
|
||||
StringBuilder buf = _processor.getRequest().getRootURL();
|
||||
StringBuilder buf = _channel.getRequest().getRootURL();
|
||||
if (location.startsWith("/"))
|
||||
buf.append(location);
|
||||
else
|
||||
{
|
||||
String path=_processor.getRequest().getRequestURI();
|
||||
String path=_channel.getRequest().getRequestURI();
|
||||
String parent=(path.endsWith("/"))?path:URIUtil.parentPath(path);
|
||||
location=URIUtil.addPaths(parent,location);
|
||||
if(location==null)
|
||||
|
@ -446,7 +444,7 @@ public class Response implements HttpServletResponse
|
|||
throw new IllegalArgumentException();
|
||||
if (!canonical.equals(path))
|
||||
{
|
||||
buf = _processor.getRequest().getRootURL();
|
||||
buf = _channel.getRequest().getRootURL();
|
||||
buf.append(URIUtil.encodePath(canonical));
|
||||
if (uri.getQuery()!=null)
|
||||
{
|
||||
|
@ -475,7 +473,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setDateHeader(String name, long date)
|
||||
{
|
||||
if (!_processor.isIncluding())
|
||||
if (!_channel.isIncluding())
|
||||
_fields.putDateField(name, date);
|
||||
}
|
||||
|
||||
|
@ -485,7 +483,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addDateHeader(String name, long date)
|
||||
{
|
||||
if (!_processor.isIncluding())
|
||||
if (!_channel.isIncluding())
|
||||
_fields.addDateField(name, date);
|
||||
}
|
||||
|
||||
|
@ -499,7 +497,7 @@ public class Response implements HttpServletResponse
|
|||
setContentType(value);
|
||||
else
|
||||
{
|
||||
if (_processor.isIncluding())
|
||||
if (_channel.isIncluding())
|
||||
return;
|
||||
|
||||
_fields.put(name, value);
|
||||
|
@ -523,7 +521,7 @@ public class Response implements HttpServletResponse
|
|||
setContentType(value);
|
||||
else
|
||||
{
|
||||
if (_processor.isIncluding())
|
||||
if (_channel.isIncluding())
|
||||
{
|
||||
if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
|
||||
name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
|
||||
|
@ -575,7 +573,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addHeader(String name, String value)
|
||||
{
|
||||
if (_processor.isIncluding())
|
||||
if (_channel.isIncluding())
|
||||
{
|
||||
if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
|
||||
name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
|
||||
|
@ -599,7 +597,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setIntHeader(String name, int value)
|
||||
{
|
||||
if (!_processor.isIncluding())
|
||||
if (!_channel.isIncluding())
|
||||
{
|
||||
_fields.putLongField(name, value);
|
||||
if (HttpHeader.CONTENT_LENGTH.is(name))
|
||||
|
@ -613,7 +611,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addIntHeader(String name, int value)
|
||||
{
|
||||
if (!_processor.isIncluding())
|
||||
if (!_channel.isIncluding())
|
||||
{
|
||||
_fields.add(name, Integer.toString(value));
|
||||
if (HttpHeader.CONTENT_LENGTH.is(name))
|
||||
|
@ -638,7 +636,7 @@ public class Response implements HttpServletResponse
|
|||
{
|
||||
if (sc<=0)
|
||||
throw new IllegalArgumentException();
|
||||
if (!_processor.isIncluding())
|
||||
if (!_channel.isIncluding())
|
||||
{
|
||||
_status=sc;
|
||||
_reason=sm;
|
||||
|
@ -680,7 +678,7 @@ public class Response implements HttpServletResponse
|
|||
if (_outputState==Output.WRITER)
|
||||
throw new IllegalStateException("WRITER");
|
||||
|
||||
ServletOutputStream out = _processor.getOutputStream();
|
||||
ServletOutputStream out = _channel.getOutputStream();
|
||||
_outputState=Output.STREAM;
|
||||
return out;
|
||||
}
|
||||
|
@ -721,7 +719,7 @@ public class Response implements HttpServletResponse
|
|||
}
|
||||
|
||||
/* construct Writer using correct encoding */
|
||||
_writer = _processor.getPrintWriter(encoding);
|
||||
_writer = _channel.getPrintWriter(encoding);
|
||||
}
|
||||
_outputState=Output.WRITER;
|
||||
return _writer;
|
||||
|
@ -737,13 +735,13 @@ public class Response implements HttpServletResponse
|
|||
// Protect from setting after committed as default handling
|
||||
// of a servlet HEAD request ALWAYS sets _content length, even
|
||||
// if the getHandling committed the response!
|
||||
if (isCommitted() || _processor.isIncluding())
|
||||
if (isCommitted() || _channel.isIncluding())
|
||||
return;
|
||||
_contentLength=len;
|
||||
_fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), (long)len);
|
||||
|
||||
if (_contentLength>0)
|
||||
checkAllContentWritten(_processor.getOutputStream().getWritten());
|
||||
checkAllContentWritten(_channel.getOutputStream().getWritten());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -784,7 +782,7 @@ public class Response implements HttpServletResponse
|
|||
// Protect from setting after committed as default handling
|
||||
// of a servlet HEAD request ALWAYS sets _content length, even
|
||||
// if the getHandling committed the response!
|
||||
if (isCommitted() || _processor.isIncluding())
|
||||
if (isCommitted() || _channel.isIncluding())
|
||||
return;
|
||||
_contentLength=len;
|
||||
_fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), len);
|
||||
|
@ -796,7 +794,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setCharacterEncoding(String encoding)
|
||||
{
|
||||
if (_processor.isIncluding())
|
||||
if (_channel.isIncluding())
|
||||
return;
|
||||
|
||||
if (_outputState==Output.NONE && !isCommitted())
|
||||
|
@ -833,7 +831,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setContentType(String contentType)
|
||||
{
|
||||
if (isCommitted() || _processor.isIncluding())
|
||||
if (isCommitted() || _channel.isIncluding())
|
||||
return;
|
||||
|
||||
if (contentType==null)
|
||||
|
@ -870,7 +868,7 @@ public class Response implements HttpServletResponse
|
|||
{
|
||||
if (isCommitted())
|
||||
throw new IllegalStateException("Committed or content written");
|
||||
_controller.increaseContentBufferSize(size);
|
||||
_channel.increaseContentBufferSize(size);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -879,7 +877,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public int getBufferSize()
|
||||
{
|
||||
return _controller.getContentBufferSize();
|
||||
return _channel.getContentBufferSize();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -888,7 +886,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void flushBuffer() throws IOException
|
||||
{
|
||||
_controller.flushResponse();
|
||||
_channel.flushResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -906,7 +904,7 @@ public class Response implements HttpServletResponse
|
|||
HttpFields response_fields=_fields;
|
||||
|
||||
response_fields.clear();
|
||||
String connection=_processor.getRequestFields().getStringField(HttpHeader.CONNECTION);
|
||||
String connection=_channel.getRequestFields().getStringField(HttpHeader.CONNECTION);
|
||||
if (connection!=null)
|
||||
{
|
||||
String[] values = connection.split(",");
|
||||
|
@ -923,7 +921,7 @@ public class Response implements HttpServletResponse
|
|||
break;
|
||||
|
||||
case KEEP_ALIVE:
|
||||
if (HttpVersion.HTTP_1_0.is(_processor.getRequest().getProtocol()))
|
||||
if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol()))
|
||||
response_fields.put(HttpHeader.CONNECTION,HttpHeaderValue.KEEP_ALIVE.toString());
|
||||
break;
|
||||
case TE:
|
||||
|
@ -960,10 +958,10 @@ public class Response implements HttpServletResponse
|
|||
{
|
||||
case STREAM:
|
||||
case WRITER:
|
||||
_processor.getOutputStream().reset();
|
||||
_channel.getOutputStream().reset();
|
||||
}
|
||||
|
||||
_controller.resetBuffer();
|
||||
_channel.resetBuffer();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -972,7 +970,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public boolean isCommitted()
|
||||
{
|
||||
return _controller.isResponseCommitted();
|
||||
return _channel.isResponseCommitted();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -981,7 +979,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setLocale(Locale locale)
|
||||
{
|
||||
if (locale == null || isCommitted() ||_processor.isIncluding())
|
||||
if (locale == null || isCommitted() ||_channel.isIncluding())
|
||||
return;
|
||||
|
||||
_locale = locale;
|
||||
|
@ -990,10 +988,10 @@ public class Response implements HttpServletResponse
|
|||
if (_outputState!=Output.NONE )
|
||||
return;
|
||||
|
||||
if (_processor.getRequest().getContext()==null)
|
||||
if (_channel.getRequest().getContext()==null)
|
||||
return;
|
||||
|
||||
String charset = _processor.getRequest().getContext().getContextHandler().getLocaleEncoding(locale);
|
||||
String charset = _channel.getRequest().getContext().getContextHandler().getLocaleEncoding(locale);
|
||||
|
||||
if (charset!=null && charset.length()>0 && _characterEncoding==null)
|
||||
setCharacterEncoding(charset);
|
||||
|
@ -1036,7 +1034,7 @@ public class Response implements HttpServletResponse
|
|||
public void complete()
|
||||
throws IOException
|
||||
{
|
||||
_controller.completeResponse();
|
||||
_channel.completeResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -335,7 +335,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
* or after the entire request has been received (for short requests of known length), or
|
||||
* on the dispatch of an async request.
|
||||
*/
|
||||
public void handle(HttpProcessor connection) throws IOException, ServletException
|
||||
public void handle(HttpChannel connection) throws IOException, ServletException
|
||||
{
|
||||
final String target=connection.getRequest().getPathInfo();
|
||||
final Request request=connection.getRequest();
|
||||
|
@ -357,7 +357,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
* or after the entire request has been received (for short requests of known length), or
|
||||
* on the dispatch of an async request.
|
||||
*/
|
||||
public void handleAsync(HttpProcessor connection) throws IOException, ServletException
|
||||
public void handleAsync(HttpChannel connection) throws IOException, ServletException
|
||||
{
|
||||
final AsyncContinuation async = connection.getRequest().getAsyncContinuation();
|
||||
final AsyncContinuation.AsyncEventState state = async.getAsyncEventState();
|
||||
|
|
Loading…
Reference in New Issue