类 HttpTunnelServer
- java.lang.Object
- org.springframework.boot.devtools.tunnel.server.HttpTunnelServer
public class HttpTunnelServer extends Object
A server that can be used to tunnel TCP traffic over HTTP. Similar in design to the Bidirectional-streams Over Synchronous HTTP (BOSH) XMPP extension protocol, the server uses long polling with HTTP requests held open until a response is available. A typical traffic pattern would be as follows:[ CLIENT ] [ SERVER ] | (a) Initial empty request | |------------------------------>| | (b) Data I | -->|------------------------------>|---> | Response I (a) | <--|<------------------------------|<--- | | | (c) Data II | -->|------------------------------>|---> | Response II (b) | <--|<------------------------------|<--- . . . .
Each incoming request is held open to be used to carry the next available response. The server will hold at most two connections open at any given time.Requests should be made using HTTP GET or POST (depending if there is a payload), with any payload contained in the body. The following response codes can be returned from the server:
Status Meaning 200 (OK) Data payload response. 204 (No Content) The long poll has timed out and the client should start a new request. 429 (Too many requests) There are already enough connections open, this one can be dropped. 410 (Gone) The target server has disconnected. 503 (Service Unavailable) The target server is unavailable Requests and responses that contain payloads include a
x-seq
header that contains a running sequence number (used to ensure data is applied in the correct order). The first request containing a payload should have ax-seq
value of1
.- 从以下版本开始:
- 1.3.0
- 另请参阅:
HttpTunnelConnection
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static class
HttpTunnelServer.HttpConnection
Encapsulates a HTTP request/response pair.protected class
HttpTunnelServer.ServerThread
The main server thread used to transfer tunnel traffic.
构造器概要
构造器 构造器 说明 HttpTunnelServer(TargetServerConnection serverConnection)
Creates a newHttpTunnelServer
instance.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected HttpTunnelServer.ServerThread
getServerThread()
Returns the active server thread, creating and starting it if necessary.protected void
handle(HttpTunnelServer.HttpConnection httpConnection)
Handle an incoming HTTP connection.void
handle(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)
Handle an incoming HTTP connection.void
setDisconnectTimeout(long disconnectTimeout)
Set the maximum amount of time to wait for a client before closing the connection.void
setLongPollTimeout(int longPollTimeout)
Set the long poll timeout for the server.
构造器详细资料
HttpTunnelServer
public HttpTunnelServer(TargetServerConnection serverConnection)
Creates a newHttpTunnelServer
instance.- 参数:
serverConnection
- the connection to the target server
方法详细资料
handle
public void handle(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response) throws IOException
Handle an incoming HTTP connection.- 参数:
request
- the HTTP requestresponse
- the HTTP response- 抛出:
IOException
- in case of I/O errors
handle
protected void handle(HttpTunnelServer.HttpConnection httpConnection) throws IOException
Handle an incoming HTTP connection.- 参数:
httpConnection
- the HTTP connection- 抛出:
IOException
- in case of I/O errors
getServerThread
protected HttpTunnelServer.ServerThread getServerThread() throws IOException
Returns the active server thread, creating and starting it if necessary.- 返回:
- the
ServerThread
(nevernull
) - 抛出:
IOException
- in case of I/O errors
setLongPollTimeout
public void setLongPollTimeout(int longPollTimeout)
Set the long poll timeout for the server.- 参数:
longPollTimeout
- the long poll timeout in milliseconds
setDisconnectTimeout
public void setDisconnectTimeout(long disconnectTimeout)
Set the maximum amount of time to wait for a client before closing the connection.- 参数:
disconnectTimeout
- the disconnect timeout in milliseconds