Fixes #3311 - Ability to serve HTTP and HTTPS from the same port.

Fixed handling of upgradeTo() in case of null buffers.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2019-01-31 17:15:07 +01:00
parent ccda1ee5f6
commit 5061a5ca30
3 changed files with 13 additions and 8 deletions

View File

@ -427,15 +427,16 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
if (LOG.isDebugEnabled())
LOG.debug("{} upgrading from {} to {}", this, old_connection, newConnection);
ByteBuffer prefilled = (old_connection instanceof Connection.UpgradeFrom)
?((Connection.UpgradeFrom)old_connection).onUpgradeFrom():null;
ByteBuffer buffer = (old_connection instanceof Connection.UpgradeFrom) ?
((Connection.UpgradeFrom)old_connection).onUpgradeFrom() :
null;
old_connection.onClose();
old_connection.getEndPoint().setConnection(newConnection);
if (newConnection instanceof Connection.UpgradeTo)
((Connection.UpgradeTo)newConnection).onUpgradeTo(prefilled);
else if (BufferUtil.hasContent(prefilled))
throw new IllegalStateException();
((Connection.UpgradeTo)newConnection).onUpgradeTo(buffer);
else if (BufferUtil.hasContent(buffer))
throw new IllegalStateException("Cannot upgrade: " + newConnection + " does not implement " + Connection.UpgradeTo.class.getName());
newConnection.onOpen();
}

View File

@ -269,8 +269,11 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr
@Override
public void onUpgradeTo(ByteBuffer buffer)
{
acquireEncryptedInput();
BufferUtil.append(_encryptedInput, buffer);
if (BufferUtil.hasContent(buffer))
{
acquireEncryptedInput();
BufferUtil.append(_encryptedInput, buffer);
}
}
@Override

View File

@ -199,7 +199,8 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
@Override
public void onUpgradeTo(ByteBuffer buffer)
{
BufferUtil.append(getRequestBuffer(), buffer);
if (BufferUtil.hasContent(buffer))
BufferUtil.append(getRequestBuffer(), buffer);
}
@Override