Revert "Issue #612 Http Trailers"

This reverts commit 5011f071ff.
This commit is contained in:
Greg Wilkins 2017-01-11 17:59:00 +11:00
parent 5011f071ff
commit 6da563f43e
1 changed files with 60 additions and 88 deletions

View File

@ -108,15 +108,6 @@ public class HttpParser
*/
public final static Trie<HttpField> CACHE = new ArrayTrie<>(2048);
// States
public enum FieldState
{
FIELD,
IN_NAME,
VALUE,
IN_VALUE,
}
// States
public enum State
{
@ -131,13 +122,17 @@ public class HttpParser
REASON,
PROXY,
HEADER,
HEADER_IN_NAME,
HEADER_VALUE,
HEADER_IN_VALUE,
CONTENT,
EOF_CONTENT,
CHUNKED_CONTENT,
CHUNK_SIZE,
CHUNK_PARAMS,
CHUNK,
TRAILER,
CHUNK_TRAILER,
CHUNK_END,
END,
CLOSE, // The associated stream/endpoint should be closed
CLOSED // The associated stream/endpoint is at EOF
@ -164,7 +159,6 @@ public class HttpParser
/* ------------------------------------------------------------------------------- */
private volatile State _state=State.START;
private volatile FieldState _fieldState=FieldState.FIELD;
private volatile boolean _eof;
private HttpMethod _method;
private String _methodString;
@ -959,18 +953,6 @@ public class HttpParser
_field=null;
}
private void parsedTrailer()
{
// handler last header if any. Delayed to here just in case there was a continuation line (above)
if (_headerString!=null || _valueString!=null)
_handler.parsedTrailer(_field!=null?_field:new HttpField(_header,_headerString,_valueString));
_headerString=_valueString=null;
_header=null;
_value=null;
_field=null;
}
private long convertContentLength(String valueString)
{
try
@ -988,12 +970,12 @@ public class HttpParser
/*
* Parse the message headers and return true if the handler has signaled for a return
*/
protected boolean parseFields(ByteBuffer buffer)
protected boolean parseHeaders(ByteBuffer buffer)
{
boolean handle=false;
// Process headers
while ((_state==State.HEADER || _state==State.TRAILER) && buffer.hasRemaining() && !handle)
while (_state.ordinal()<State.CONTENT.ordinal() && buffer.hasRemaining() && !handle)
{
// process each character
byte ch=next(buffer);
@ -1006,9 +988,9 @@ public class HttpParser
throw new BadMessageException(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE_431);
}
switch (_fieldState)
switch (_state)
{
case FIELD:
case HEADER:
switch(ch)
{
case HttpTokens.COLON:
@ -1031,27 +1013,19 @@ public class HttpParser
_length++;
_valueString=null;
}
setState(FieldState.VALUE);
setState(State.HEADER_VALUE);
break;
}
case HttpTokens.LINE_FEED:
{
// process previous header
if (_state==State.HEADER)
parsedHeader();
else
parsedTrailer();
parsedHeader();
_contentPosition=0;
// End of headers or trailers?
if (_state==State.TRAILER)
{
setState(State.END);
return _handler.messageComplete();
}
// End of headers!
// Was there a required host header?
if (!_host && _version==HttpVersion.HTTP_1_1 && _requestHandler!=null)
{
@ -1151,7 +1125,7 @@ public class HttpParser
if (v==null)
{
// Header only
setState(FieldState.VALUE);
setState(State.HEADER_VALUE);
_string.setLength(0);
_length=0;
buffer.position(buffer.position()+n.length()+1);
@ -1167,7 +1141,7 @@ public class HttpParser
{
_field=field;
_valueString=v;
setState(FieldState.IN_VALUE);
setState(State.HEADER_IN_VALUE);
if (b==HttpTokens.CARRIAGE_RETURN)
{
@ -1180,7 +1154,7 @@ public class HttpParser
}
else
{
setState(FieldState.IN_VALUE);
setState(State.HEADER_IN_VALUE);
setString(v);
buffer.position(pos);
break;
@ -1190,7 +1164,7 @@ public class HttpParser
}
// New header
setState(FieldState.IN_NAME);
setState(State.HEADER_IN_NAME);
_string.setLength(0);
_string.append((char)ch);
_length=1;
@ -1199,7 +1173,7 @@ public class HttpParser
}
break;
case IN_NAME:
case HEADER_IN_NAME:
if (ch==HttpTokens.COLON)
{
if (_headerString==null)
@ -1209,7 +1183,7 @@ public class HttpParser
}
_length=-1;
setState(FieldState.VALUE);
setState(State.HEADER_VALUE);
break;
}
@ -1240,18 +1214,18 @@ public class HttpParser
_valueString="";
_length=-1;
setState(FieldState.FIELD);
setState(State.HEADER);
break;
}
throw new IllegalCharacterException(_state,ch,buffer);
case VALUE:
case HEADER_VALUE:
if (ch>HttpTokens.SPACE || ch<0)
{
_string.append((char)(0xff&ch));
_length=_string.length();
setState(FieldState.IN_VALUE);
setState(State.HEADER_IN_VALUE);
break;
}
@ -1265,12 +1239,12 @@ public class HttpParser
_valueString="";
_length=-1;
setState(FieldState.FIELD);
setState(State.HEADER);
break;
}
throw new IllegalCharacterException(_state,ch,buffer);
case IN_VALUE:
case HEADER_IN_VALUE:
if (ch>=HttpTokens.SPACE || ch<0 || ch==HttpTokens.TAB)
{
if (_valueString!=null)
@ -1293,7 +1267,7 @@ public class HttpParser
_valueString=takeString();
_length=-1;
}
setState(FieldState.FIELD);
setState(State.HEADER);
break;
}
@ -1340,14 +1314,14 @@ public class HttpParser
}
// parse headers
if (_state== State.HEADER)
if (_state.ordinal()>= State.HEADER.ordinal() && _state.ordinal()<State.CONTENT.ordinal())
{
if (parseFields(buffer))
if (parseHeaders(buffer))
return true;
}
// parse content
if (_state.ordinal()>= State.CONTENT.ordinal() && _state.ordinal()<State.TRAILER.ordinal())
if (_state.ordinal()>= State.CONTENT.ordinal() && _state.ordinal()<State.END.ordinal())
{
// Handle HEAD response
if (_responseStatus>0 && _headResponse)
@ -1362,13 +1336,6 @@ public class HttpParser
}
}
// parse headers
if (_state==State.TRAILER)
{
if (parseFields(buffer))
return true;
}
// handle end states
if (_state==State.END)
{
@ -1415,22 +1382,16 @@ public class HttpParser
break;
case EOF_CONTENT:
case TRAILER:
if (_fieldState==FieldState.FIELD)
{
// Be forgiving of missing last CRLF
setState(State.CLOSED);
return _handler.messageComplete();
}
case CHUNK_END:
setState(State.CLOSED);
_handler.earlyEOF();
break;
return _handler.messageComplete();
case CONTENT:
case CHUNKED_CONTENT:
case CHUNK_SIZE:
case CHUNK_PARAMS:
case CHUNK:
case CHUNK_TRAILER:
setState(State.CLOSED);
_handler.earlyEOF();
break;
@ -1514,7 +1475,7 @@ public class HttpParser
// Handle _content
byte ch;
while (_state.ordinal() < State.TRAILER.ordinal() && remaining>0)
while (_state.ordinal() < State.END.ordinal() && remaining>0)
{
switch (_state)
{
@ -1582,7 +1543,7 @@ public class HttpParser
if (ch == HttpTokens.LINE_FEED)
{
if (_chunkLength == 0)
setState(State.TRAILER);
setState(State.CHUNK_END);
else
setState(State.CHUNK);
}
@ -1599,7 +1560,7 @@ public class HttpParser
if (ch == HttpTokens.LINE_FEED)
{
if (_chunkLength == 0)
setState(State.TRAILER);
setState(State.CHUNK_END);
else
setState(State.CHUNK);
}
@ -1630,6 +1591,31 @@ public class HttpParser
break;
}
case CHUNK_END:
{
ch=next(buffer);
if (ch==0)
break;
if (ch == HttpTokens.LINE_FEED)
{
setState(State.END);
return _handler.messageComplete();
}
setState(State.CHUNK_TRAILER);
break;
}
case CHUNK_TRAILER:
{
// TODO handle chunk trailer values
ch=next(buffer);
if (ch==0)
break;
if (ch == HttpTokens.LINE_FEED)
setState(State.CHUNK_END);
break;
}
case CLOSED:
{
BufferUtil.clear(buffer);
@ -1701,14 +1687,6 @@ public class HttpParser
_state=state;
}
/* ------------------------------------------------------------------------------- */
protected void setState(FieldState state)
{
if (DEBUG)
LOG.debug("{}:{} --> {}",_state,_field,state);
_fieldState=state;
}
/* ------------------------------------------------------------------------------- */
public Trie<HttpField> getFieldCache()
{
@ -1766,12 +1744,6 @@ public class HttpParser
* @param field The field parsed
*/
public void parsedHeader(HttpField field);
/**
* This is the method called by parser when a HTTP Trailer name and value is found
* @param field The field parsed
*/
public default void parsedTrailer(HttpField field) {}
/* ------------------------------------------------------------ */
/** Called to signal that an EOF was received unexpectedly