30#ifndef A11_NET_WEBSOCKET_WIRE_STREAM_H_
31#define A11_NET_WEBSOCKET_WIRE_STREAM_H_
38#include <absl/base/nullability.h>
39#include <absl/status/status.h>
40#include <absl/status/statusor.h>
87 struct ConstructorToken {};
100 static absl::StatusOr<std::shared_ptr<WebSocketWireStream>>
CreateClient(
113 return request_path_;
123 return request_headers_;
130 static absl::StatusOr<std::shared_ptr<WebSocketWireStream>> CreateAccepted(
131 HttpRequest request, std::shared_ptr<Http2ResponseWriter> response,
136 std::string request_path_;
188 std::function<
a11::Task(std::shared_ptr<WebSocketWireStream>)>;
198 :
public std::enable_shared_from_this<WebSocketWireServer> {
207 static absl::StatusOr<std::shared_ptr<WebSocketWireServer>>
Create(
214 absl::StatusOr<std::uint16_t>
port()
const;
216 [[nodiscard]]
bool running()
const;
218 [[nodiscard]]
void* absl_nullable
GetImpl()
const;
224 : state_(std::move(state)) {}
226 std::shared_ptr<State> state_;
Shared WireStream lifecycle and framing for binary channels.
Definition channel_wire_stream.h:69
Accepts inbound WebSocket connections and hands each to a callback.
Definition websocket_wire_stream.h:198
bool running() const
Definition websocket_wire_stream.cc:287
absl::StatusOr< std::uint16_t > port() const
Definition websocket_wire_stream.cc:279
~WebSocketWireServer()
Definition websocket_wire_stream.cc:266
absl::Status Stop()
Stops the server and closes the listening socket.
Definition websocket_wire_stream.cc:270
void *absl_nullable GetImpl() const
Definition websocket_wire_stream.cc:292
static absl::StatusOr< std::shared_ptr< WebSocketWireServer > > Create(OnWebSocketStream on_stream, WebSocketServerOptions options={})
Starts a WebSocket server accepting A11 connections.
Definition websocket_wire_stream.cc:185
A WireStream that carries A11 traffic over a client or accepted WebSocket.
Definition websocket_wire_stream.h:85
WebSocketWireStream(ConstructorToken, std::shared_ptr< State > state)
Definition websocket_wire_stream.h:126
const HttpHeaders & GetRequestHeaders() const
The headers the accepted request carried.
Definition websocket_wire_stream.h:122
static absl::StatusOr< std::shared_ptr< WebSocketWireStream > > CreateClient(const std::string &url, WireStreamOptions options={}, WebSocketClientOptions websocket_options={})
Dials a WebSocket endpoint and returns a WireStream over it.
Definition websocket_wire_stream.cc:96
const std::string & GetRequestPath() const
The path this stream was accepted on, query string included.
Definition websocket_wire_stream.h:112
GET /actions, on whichever server happens to hold the port.
Completion values used by every asynchronous A11 operation.
A11's nghttp2 HTTP/2 client, server, and streaming primitives.
std::function< a11::Task(std::shared_ptr< WebSocketWireStream >)> OnWebSocketStream
Callback invoked with a fresh WireStream for each accepted connection.
Definition websocket_wire_stream.h:188
std::vector< std::pair< std::string, std::string > > HttpHeaders
An ordered list of (name, value) HTTP/2 header fields.
Definition http2.h:70
Future< Unit > Task
Asynchronous operation whose only successful result is completion itself.
Definition future.h:411
Packetisation and incomplete-message bounds for a binary WireStream.
Definition channel_wire_stream.h:46
Where and whether a server answers discovery over plain HTTP.
Definition describe_endpoint.h:72
Body-size limits, buffering thresholds, deadline, TLS, and HTTP protocol negotiation for an HTTP clie...
Definition http2.h:150
A parsed HTTP/2 request: pseudo-headers, fields, and body.
Definition http2.h:90
Client-side tuning for a WebSocketWireStream connection.
Definition websocket_wire_stream.h:58
absl::Time handshake_deadline
How long the handshake alone may take.
Definition websocket_wire_stream.h:71
HttpHeaders headers
Extra WebSocket handshake headers.
Definition websocket_wire_stream.h:60
absl::Status Validate() const
Definition websocket_wire_stream.cc:89
ChannelFramingOptions framing
Packet splitting and reassembly bounds.
Definition websocket_wire_stream.h:61
Http2Options http2_options
HTTP/2 connection and TLS policy.
Definition websocket_wire_stream.h:59
Listen address, path, and per-stream defaults for a WebSocketWireServer.
Definition websocket_wire_stream.h:150
std::string path_prefix
Also accept anything under this prefix, as well as path.
Definition websocket_wire_stream.h:160
ServerHeaderOptions headers
Response-header policy for this port's HTTP surface – the Server header, cross-origin access and cach...
Definition websocket_wire_stream.h:180
std::uint16_t port
Listen port; zero requests an ephemeral port.
Definition websocket_wire_stream.h:162
std::string bind_address
Local listen address.
Definition websocket_wire_stream.h:161
ChannelFramingOptions framing
Framing for accepted streams.
Definition websocket_wire_stream.h:164
Http2Options http2_options
Server HTTP/2 and TLS policy.
Definition websocket_wire_stream.h:165
std::string path
Exact WebSocket endpoint path.
Definition websocket_wire_stream.h:151
DescribeEndpointOptions describe
GET /actions on this same port, when something above filled in the handler.
Definition websocket_wire_stream.h:172
WireStreamOptions stream_options
Defaults for accepted streams.
Definition websocket_wire_stream.h:163
absl::Status Validate() const
Definition websocket_wire_stream.cc:154
Definition websocket_wire_stream.cc:173
Buffering, sizing, and deadline limits for a WireStream endpoint.
Definition wire_stream.h:58
A11's transport abstraction: the bidirectional WireStream channel and the options/callbacks that driv...