The live HTTP/1.1 server (Effect's NodeHttpServer), on the standard
library's asyncio streams: no ASGI server needed.
::
main = server.serve(app).pipe(layer.provide(live_server.layer(port=8080)))Requests are read with keep-alive, Content-Length or chunked bodies,
Expect: 100-continue (the 100 is sent when the app first reads the
body) and upgrades (Upgrade: websocket speaks RFC 6455, as ws
does under Node, with permessage-deflate when websocket_per_message_deflate
is set); responses get Node's framing and headers. When the
serving scope closes the server stops accepting, closes idle connections
and gives the busy ones graceful_shutdown_timeout to finish: as Node's
server does, they go on answering keep-alive requests until they have been
idle for keep_alive_timeout.
Re-exports#
Values#
| Attribute | Type | Description |
|---|---|---|
layer_services | Layer[Path | HttpPlatform | FileSystem | Generator] | What a live server's apps use: |
Classes#
Functions#
make#
make(**options) -> Effect[HttpServerService, SocketServerError, Scope]An HttpServer listening on host:port until the scope closes.
| Parameter | Type | Description |
|---|---|---|
options | Unpack[Options] = {} |
Returns Effect[HttpServerService, SocketServerError, Scope]
def make(**options: Unpack[Options]) -> Effect[HttpServerService, SocketServerError, Scope]:
"""An ``HttpServer`` listening on ``host:port`` until the scope closes."""
host, port = options.get("host"), options.get("port", 0)
return _make(lambda factory: get_loop().create_server(factory, host, port), "http", options)make_unix#
make_unix(path, **options) -> Effect[HttpServerService, SocketServerError, Scope]An HttpServer on the Unix socket at path.
| Parameter | Type | Description |
|---|---|---|
path | str | |
options | Unpack[Options] = {} |
Returns Effect[HttpServerService, SocketServerError, Scope]
def make_unix(
path: str, **options: Unpack[Options]
) -> Effect[HttpServerService, SocketServerError, Scope]:
"""An ``HttpServer`` on the Unix socket at ``path``."""
return _make(lambda factory: get_loop().create_unix_server(factory, path), "http", options)make_tls#
make_tls(**options) -> Effect[HttpServerService, SocketServerError, Scope]An HTTPS server: requests' protocol is https.
| Parameter | Type | Description |
|---|---|---|
options | Unpack[TlsOptions] = {} |
Returns Effect[HttpServerService, SocketServerError, Scope]
def make_tls(**options: Unpack[TlsOptions]) -> Effect[HttpServerService, SocketServerError, Scope]:
"""An HTTPS server: requests' ``protocol`` is ``https``."""
key = options["key"]
tls = TlsUpgradeOptions(
cert=options["cert"], key=key if isinstance(key, Redacted) else Redacted(key)
)
def body() -> Effect[HttpServerService, SocketServerError, Scope]:
try:
context = server_context(tls)
except (OSError, ValueError) as cause:
return fail(SocketServerError(SocketServerOpenError(cause)))
host, port = options.get("host"), options.get("port", 0)
handshake_timeout = from_input_unsafe(options.get("handshake_timeout", "120 seconds"))
return _make(
lambda factory: get_loop().create_server(factory, host, port),
"https",
options,
Tls(context, handshake_timeout),
)
return suspend(body)layer_server#
layer_server(**options) -> Layer[HttpServer, SocketServerError]| Parameter | Type | Description |
|---|---|---|
options | Unpack[Options] = {} |
Returns Layer[HttpServer, SocketServerError]
def layer_server(**options: Unpack[Options]) -> Layer[HttpServer, SocketServerError]:
return layer_effect(HttpServer, make(**options))layer#
layer(**options) -> Layer[HttpServer | Path | HttpPlatform | FileSystem | Generator, SocketServerError]The server and the services its apps use.
| Parameter | Type | Description |
|---|---|---|
options | Unpack[Options] = {} |
Returns Layer[HttpServer | Path | HttpPlatform | FileSystem | Generator, SocketServerError]
def layer(
**options: Unpack[Options],
) -> Layer[HttpServer | Path | HttpPlatform | FileSystem | Generator, SocketServerError]:
"""The server and the services its apps use."""
return merge(layer_server(**options), layer_services)layer_test#
layer_test(**options) -> Layer[HttpServer | Path | HttpPlatform | FileSystem | Generator | HttpClient, SocketServerError]A server on a free loopback port, its services, and an HttpClient
(httpx) sending to it.
| Parameter | Type | Description |
|---|---|---|
options | Unpack[Options] = {} |
Returns Layer[HttpServer | Path | HttpPlatform | FileSystem | Generator | HttpClient, SocketServerError]
def layer_test(
**options: Unpack[Options],
) -> Layer[
HttpServer | Path | HttpPlatform | FileSystem | Generator | HttpClient, SocketServerError
]:
"""A server on a free loopback port, its services, and an ``HttpClient``
(httpx) sending to it."""
server = layer(**{"host": "127.0.0.1", **options})
return layer_test_client.pipe(provide_merge(httpx_layer)).pipe(provide_merge(server))