Cleanup to avoid duplication method (noticed while reviewing #2977)
This commit is contained in:
parent
64e561dcb1
commit
5c8d3f041b
|
@ -33,7 +33,7 @@ public class MetaDataBuilder
|
||||||
{
|
{
|
||||||
private final int _maxSize;
|
private final int _maxSize;
|
||||||
private int _size;
|
private int _size;
|
||||||
private int _status=-1;
|
private Integer _status;
|
||||||
private String _method;
|
private String _method;
|
||||||
private HttpScheme _scheme;
|
private HttpScheme _scheme;
|
||||||
private HostPortHttpField _authority;
|
private HostPortHttpField _authority;
|
||||||
|
@ -47,7 +47,7 @@ public class MetaDataBuilder
|
||||||
/**
|
/**
|
||||||
* @param maxHeadersSize The maximum size of the headers, expressed as total name and value characters.
|
* @param maxHeadersSize The maximum size of the headers, expressed as total name and value characters.
|
||||||
*/
|
*/
|
||||||
MetaDataBuilder(int maxHeadersSize)
|
protected MetaDataBuilder(int maxHeadersSize)
|
||||||
{
|
{
|
||||||
_maxSize=maxHeadersSize;
|
_maxSize=maxHeadersSize;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class MetaDataBuilder
|
||||||
switch(header)
|
switch(header)
|
||||||
{
|
{
|
||||||
case C_STATUS:
|
case C_STATUS:
|
||||||
if(checkHeader(header, _status))
|
if(checkPseudoHeader(header, _status))
|
||||||
_status = (Integer)staticField.getStaticValue();
|
_status = (Integer)staticField.getStaticValue();
|
||||||
_response = true;
|
_response = true;
|
||||||
break;
|
break;
|
||||||
|
@ -110,8 +110,8 @@ public class MetaDataBuilder
|
||||||
switch(header)
|
switch(header)
|
||||||
{
|
{
|
||||||
case C_STATUS:
|
case C_STATUS:
|
||||||
if(checkHeader(header, _status))
|
if(checkPseudoHeader(header, _status))
|
||||||
_status = field.getIntValue();
|
_status = Integer.valueOf(field.getIntValue());
|
||||||
_response = true;
|
_response = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public class MetaDataBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamException(String messageFormat, Object... args)
|
protected void streamException(String messageFormat, Object... args)
|
||||||
{
|
{
|
||||||
HpackException.StreamException stream = new HpackException.StreamException(messageFormat, args);
|
HpackException.StreamException stream = new HpackException.StreamException(messageFormat, args);
|
||||||
if (_streamException==null)
|
if (_streamException==null)
|
||||||
|
@ -206,20 +206,7 @@ public class MetaDataBuilder
|
||||||
_streamException.addSuppressed(stream);
|
_streamException.addSuppressed(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkHeader(HttpHeader header, int value)
|
protected boolean checkPseudoHeader(HttpHeader header, Object value)
|
||||||
{
|
|
||||||
if (_fields.size()>0)
|
|
||||||
{
|
|
||||||
streamException("Pseudo header %s after fields", header.asString());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (value==-1)
|
|
||||||
return true;
|
|
||||||
streamException("Duplicate pseudo header %s", header.asString());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkPseudoHeader(HttpHeader header, Object value)
|
|
||||||
{
|
{
|
||||||
if (_fields.size()>0)
|
if (_fields.size()>0)
|
||||||
{
|
{
|
||||||
|
@ -258,22 +245,26 @@ public class MetaDataBuilder
|
||||||
return new MetaData.Request(_method,_scheme,_authority,_path,HttpVersion.HTTP_2,fields,_contentLength);
|
return new MetaData.Request(_method,_scheme,_authority,_path,HttpVersion.HTTP_2,fields,_contentLength);
|
||||||
}
|
}
|
||||||
if (_response)
|
if (_response)
|
||||||
return new MetaData.Response(HttpVersion.HTTP_2,_status,fields,_contentLength);
|
{
|
||||||
|
if (_status==null)
|
||||||
|
throw new HpackException.StreamException("No Status");
|
||||||
|
return new MetaData.Response(HttpVersion.HTTP_2, _status, fields, _contentLength);
|
||||||
|
}
|
||||||
|
|
||||||
return new MetaData(HttpVersion.HTTP_2,fields,_contentLength);
|
return new MetaData(HttpVersion.HTTP_2,fields,_contentLength);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_fields = new HttpFields(Math.max(10,fields.size()+5));
|
_fields = new HttpFields(Math.max(10, fields.size() + 5));
|
||||||
_request=false;
|
_request = false;
|
||||||
_response=false;
|
_response = false;
|
||||||
_status=-1;
|
_status = null;
|
||||||
_method=null;
|
_method = null;
|
||||||
_scheme=null;
|
_scheme = null;
|
||||||
_authority=null;
|
_authority = null;
|
||||||
_path=null;
|
_path = null;
|
||||||
_size=0;
|
_size = 0;
|
||||||
_contentLength=Long.MIN_VALUE;
|
_contentLength = Long.MIN_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue