Configuration.acceptHTTPTunnel()
Description
Appends an acceptHTTPTunnel filter to the current pipeline layout.
An acceptHTTPTunnel filter implements HTTP tunnel on the server side.
- INPUT - Data stream received from the client with a leading HTTP CONNECT request Message.
- OUTPUT - Data stream to send to the client with a leading HTTP CONNECT response Message.
- SUB-INPUT - Data stream received from the client via HTTP tunnel.
- SUB-OUTPUT - Data stream to send to the client via HTTP tunnel.
An acceptHTTPTunnel filter calls back a user handler for the input Message (expected to be an HTTP request) and outputs the Message returned from the callback as response. When the response status code is 1xx or 2xx, a sub-pipeline will be created to establish an HTTP tunnel and Data events after that initial request and response are sent back and forth between the acceptHTTPTunnel filter and the sub-pipeline.
Besides HTTP tunnel, this filter can also be used for a tunneling-like protocol upgraded from a regular HTTP session, such as WebSocket.
Syntax
pipy().pipeline().acceptHTTPTunnel(request => getResponse(request)).to(subPipelineLayout)
Parameters
acceptHTTPTunnel(handler)
A function that receives the starting request Message and returns a response Message.
The same Configuration object.
Example
pipy({_target: '',}).listen(8080).demuxHTTP().to($=>$.acceptHTTPTunnel(msg => (_target = msg.head.path, // Extracts the target from the URInew Message('OK'))).to($=>$.connect(() => _target)))