}
public void renegotiateBufferRequest(HttpServerExchange exchange, SslClientAuthMode newAuthMode) throws IOException {
int maxSize = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_BUFFERED_REQUEST_SIZE, 16384);
if (maxSize <= 0) {
throw new SSLPeerUnverifiedException("");
}
//first we need to read the request
boolean requestResetRequired = false;
StreamSourceChannel requestChannel = Connectors.getExistingRequestChannel(exchange);
if (requestChannel == null) {
requestChannel = exchange.getRequestChannel();
requestResetRequired = true;
}
Pooled<ByteBuffer> pooled = exchange.getConnection().getBufferPool().allocate();
boolean free = true; //if the pooled buffer should be freed
int usedBuffers = 0;
Pooled<ByteBuffer>[] poolArray = null;
final int bufferSize = pooled.getResource().remaining();
int allowedBuffers = ((maxSize + bufferSize - 1) / bufferSize);
poolArray = new Pooled[allowedBuffers];
poolArray[usedBuffers++] = pooled;
try {
int res;
do {
final ByteBuffer buf = pooled.getResource();
res = Channels.readBlocking(requestChannel, buf);
if (!buf.hasRemaining()) {
if (usedBuffers == allowedBuffers) {
throw new SSLPeerUnverifiedException("");
} else {
buf.flip();
pooled = exchange.getConnection().getBufferPool().allocate();
poolArray[usedBuffers++] = pooled;
}