improved handler signature

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-03-13 18:25:32 +11:00
parent d670b60e4d
commit faa32f0c71
2 changed files with 11 additions and 5 deletions

View File

@ -351,6 +351,10 @@ public class MultiPartParser
_state = State.END;
_handler.messageComplete();
}
else
{
_handler.earlyEOF();
}
return handle;
}
@ -405,6 +409,7 @@ public class MultiPartParser
if (b=='\n')
{
setState(State.BODY_PART);
_handler.startPart();
return;
}
@ -604,7 +609,7 @@ public class MultiPartParser
private void handleField()
{
if (_fieldName!=null && _fieldValue!=null)
_handler.parsedHeader(_fieldName,_fieldValue);
_handler.parsedField(_fieldName,_fieldValue);
_fieldName = _fieldValue = null;
}
@ -719,7 +724,8 @@ public class MultiPartParser
*/
public interface Handler
{
public default void parsedHeader(String name, String value) {}
public default void startPart() {}
public default void parsedField(String name, String value) {}
public default boolean headerComplete() {return false;}
public default boolean content(ByteBuffer item, boolean last) {return false;}

View File

@ -329,7 +329,7 @@ public class MultiPartParserTest
{
@Override
public void parsedHeader(String name, String value)
public void parsedField(String name, String value)
{
fields.add(name+": "+value);
}
@ -386,7 +386,7 @@ public class MultiPartParserTest
{
@Override
public void parsedHeader(String name, String value)
public void parsedField(String name, String value)
{
fields.add(name+": "+value);
}
@ -456,7 +456,7 @@ public class MultiPartParserTest
List<String> content = new ArrayList<>();
@Override
public void parsedHeader(String name, String value)
public void parsedField(String name, String value)
{
fields.add(name+": "+value);
}