public interface HttpUpgrader
An HttpUpgrader can be registered to an HttpServer by
If an HttpRequest requests to upgrade the connection to that protocol,
tryUpgrade(HttpRequest, bayou.tcp.TcpConnection) method is invoked on the upgrader.
If the upgrade is successful, the upgrader takes over the connection and
is responsible to handle the connection by the new protocol.
void init(HttpServerConf httpServerConf) throws Exception
This method is invoked before the HttpServer is started.
Async<HttpResponse> tryUpgrade(HttpRequest httpRequest, TcpConnection tcpConnection)
This is an async action. If the action completes with
upgrade is successful, this HttpUpgrader takes over the TcpConnection.
If the action completes with a
the connection remains HTTP not-upgraded, and the HttpResponse
will be written to the client. If the action fails with an Exception, it's an internal error
and the connection will be killed.
If the `httpRequest` contains a body, the body should be drained first by `read()` till EOF, before using the `tcpConnection` for new protocol.
This method is usually invoked in a
Fiber created by the http server.
If upgrade is successful, that Fiber will end; a new Fiber or Fibers can be
created for the continued handling of the tcp connection.