consumeAvailable should use number of reads instead of bytes
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
02823ecfad
commit
d66e36b746
|
@ -79,7 +79,7 @@ public class HttpConfiguration implements Dumpable
|
||||||
private boolean _relativeRedirectAllowed;
|
private boolean _relativeRedirectAllowed;
|
||||||
private HostPort _serverAuthority;
|
private HostPort _serverAuthority;
|
||||||
private SocketAddress _localAddress;
|
private SocketAddress _localAddress;
|
||||||
private long _maxUnconsumedRequestContentBytes = 1024 * 1024;
|
private int _maxUnconsumedRequestContentReads = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>An interface that allows a request object to be customized
|
* <p>An interface that allows a request object to be customized
|
||||||
|
@ -718,25 +718,25 @@ public class HttpConfiguration implements Dumpable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the maximum amount of bytes that will be read from the HttpStream if the content is not fully consumed by the
|
* Sets the maximum amount of {@link HttpStream#read()}s that can be done by the {@link HttpStream} if the content is not
|
||||||
* application. If this is unable to consume to EOF then the connection will be made non-persistent.
|
* fully consumed by the application. If this is unable to consume to EOF then the connection will be made non-persistent.
|
||||||
*
|
*
|
||||||
* @param maxUnconsumedRequestContentBytes the maximum amount of unconsumed bytes that will be read from the HttpStream.
|
* @param maxUnconsumedRequestContentReads the maximum amount of reads for unconsumed content or -1 for unlimited.
|
||||||
*/
|
*/
|
||||||
public void setMaxUnconsumedRequestContentBytes(long maxUnconsumedRequestContentBytes)
|
public void setMaxUnconsumedRequestContentReads(int maxUnconsumedRequestContentReads)
|
||||||
{
|
{
|
||||||
_maxUnconsumedRequestContentBytes = maxUnconsumedRequestContentBytes;
|
_maxUnconsumedRequestContentReads = maxUnconsumedRequestContentReads;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the maximum amount of bytes that will be read from the HttpStream if the content is not fully consumed by the
|
* Gets the maximum amount of {@link HttpStream#read()}s that can be done by the {@link HttpStream} if the content is not
|
||||||
* application. If this is unable to consume to EOF then the connection will be made non-persistent.
|
* fully consumed by the application. If this is unable to consume to EOF then the connection will be made non-persistent.
|
||||||
*
|
*
|
||||||
* @return the maximum amount of unconsumed bytes that will be read from the HttpStream.
|
* @return the maximum amount of reads for unconsumed content or -1 for unlimited.
|
||||||
*/
|
*/
|
||||||
public long getMaxUnconsumedRequestContentBytes()
|
public int getMaxUnconsumedRequestContentReads()
|
||||||
{
|
{
|
||||||
return _maxUnconsumedRequestContentBytes;
|
return _maxUnconsumedRequestContentReads;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -108,19 +108,19 @@ public interface HttpStream extends Callback
|
||||||
|
|
||||||
static Throwable consumeAvailable(HttpStream stream, HttpConfiguration httpConfig)
|
static Throwable consumeAvailable(HttpStream stream, HttpConfiguration httpConfig)
|
||||||
{
|
{
|
||||||
long consumedRequestContentBytes = 0;
|
int numReads = 0;
|
||||||
long maxUnconsumedRequestContentBytes = httpConfig.getMaxUnconsumedRequestContentBytes();
|
int maxReads = httpConfig.getMaxUnconsumedRequestContentReads();
|
||||||
while (maxUnconsumedRequestContentBytes < 0 || consumedRequestContentBytes < maxUnconsumedRequestContentBytes)
|
while (maxReads < 0 || numReads < maxReads)
|
||||||
{
|
{
|
||||||
// We can always just read again here as EOF and Error content will be persistently returned.
|
// We can always just read again here as EOF and Error content will be persistently returned.
|
||||||
Chunk content = stream.read();
|
Chunk content = stream.read();
|
||||||
|
numReads++;
|
||||||
|
|
||||||
// if we cannot read to EOF then fail the stream rather than wait for unconsumed content
|
// if we cannot read to EOF then fail the stream rather than wait for unconsumed content
|
||||||
if (content == null)
|
if (content == null)
|
||||||
return new IOException("Content not consumed");
|
return new IOException("Content not consumed");
|
||||||
|
|
||||||
// Always release any returned content. This is a noop for EOF and Error content.
|
// Always release any returned content. This is a noop for EOF and Error content.
|
||||||
consumedRequestContentBytes += content.remaining();
|
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
// if the input failed, then fail the stream for same reason
|
// if the input failed, then fail the stream for same reason
|
||||||
|
|
Loading…
Reference in New Issue