public interface HttpUpgrader
An HttpUpgrader can be registered to an HttpServer by
HttpServer.addUpgrader(protocol, httpUpgrader)
.
If an HttpRequest requests to upgrade the connection to that protocol,
the 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.
Abstract Methods | |
---|---|
void |
init(HttpServerConf httpServerConf)
Initialize this upgrader.
|
Async<HttpResponse> |
tryUpgrade(HttpRequest httpRequest,
TcpConnection tcpConnection)
Try to upgrade the http connection.
|
void init(HttpServerConf httpServerConf) throws Exception
This method is invoked before the HttpServer is started.
Exception
Async<HttpResponse> tryUpgrade(HttpRequest httpRequest, TcpConnection tcpConnection)
This is an async action. If the action completes with (HttpResponse)null
,
upgrade is successful, this HttpUpgrader takes over the TcpConnection.
If the action completes with a non-null HttpResponse
,
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.