You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9c3e23e
Browse filesBrowse the repository at this point in the historyBrowse files
feat: HttpServerSettings builds the FastAPI entrypoint's config from environment settings
One pydantic model per config dataclass in the FastAPI adapter —
HttpServerSettings, HealthSettings, MiddlewareSettings and the four
middleware settings — same fields and defaults, to_config() on each, plus
UvicornSettings typing the operational uvicorn knobs behind
HttpConfig.uvicorn_kwargs (None until set, forwarded only then; no
workers, which Server.serve() ignores). Plain BaseModels, never a
BaseSettings, nested under the name you choose; BaseServiceSettings stays
transport-neutral. The members that are code — version, unit_scope,
context_setters, custom — are arguments of to_config(). port=0 is
rejected unless allow_ephemeral_port=True, as on MetricsSettings.
Closes#61
|`custom`|`MiddlewareSettings.to_config`|`()`| Middleware classes and their kwargs |
143
+
144
+
`fastapi_kwargs` and `uvicorn_kwargs` stay dict fields, JSON in the environment
145
+
(`SERVER__FASTAPI_KWARGS='{"debug": true}'`); anything that is not JSON — a `lifespan`, say — goes
146
+
onto the returned config afterwards, `config.fastapi_kwargs["lifespan"] = lifespan`.
147
+
148
+
`port=0` is rejected unless `allow_ephemeral_port=True`, as on
149
+
[`MetricsSettings`](../concepts/settings.md#validation-instead-of-silent-fallbacks): `0` only ever
150
+
arrives here from configuration (`SERVER__PORT`, one keystroke from `8000`), and a pod on an
151
+
ephemeral port is one no probe or load balancer reaches. `HttpConfig(port=0)` itself keeps working
152
+
and reports what it got through `bound_port`. CORS `allow_credentials=True` with a `*` origin fails
153
+
at load, with `server.middlewares.cors` in the error, rather than at construction.
154
+
155
+
#### The uvicorn knobs
156
+
157
+
`server.uvicorn` types the operational uvicorn arguments. Every field is `None` until set and only
158
+
a set field is forwarded, so uvicorn's own defaults apply to the rest and the model pins none of
159
+
them; `to_config()` puts exactly what was set into `HttpConfig.uvicorn_kwargs`, typed —
160
+
`SERVER__UVICORN__TIMEOUT_KEEP_ALIVE=30` arrives as the integer `30`, where the same key under a
161
+
`dict` field would arrive as the string `"30"`.
162
+
163
+
| Field | uvicorn's default | Meaning |
164
+
| --- | --- | --- |
165
+
|`proxy_headers`|`True`| Trust `X-Forwarded-*` from `forwarded_allow_ips`|
166
+
|`forwarded_allow_ips`|`127.0.0.1`| A list, a comma-separated string or `*`|
167
+
|`root_path`|`""`| ASGI root path, for an app served under a prefix |
168
+
|`server_header`, `date_header`|`True`| The `Server` and `Date` response headers |
169
+
|`timeout_keep_alive`|`5`| Seconds an idle keep-alive connection is held |
170
+
|`backlog`|`2048`| Listen backlog |
171
+
|`limit_concurrency`| none | Concurrent connections or tasks before new requests get a 503 |
172
+
|`limit_max_requests`| none | Requests served before the server exits — and the Host stops the process |
173
+
|`h11_max_incomplete_event_size`| h11's | Largest request line plus headers, bytes |
174
+
|`access_log`|`True`| uvicorn's own access log; the logging middleware writes one line per request already |
175
+
|`log_level`| none | Level of uvicorn's own loggers, `critical` … `trace`, any case |
176
+
|`ssl_keyfile`, `ssl_certfile`, `ssl_keyfile_password`, `ssl_ca_certs`, `ssl_cert_reqs`, `ssl_ciphers`| none | TLS termination in the process; uvicorn wraps the socket the runner bound |
177
+
178
+
`uvicorn_kwargs` is the escape hatch for the rest of `uvicorn.Config`'s signature and wins on a
179
+
collision, as it does on `HttpConfig` itself. A test asserts every typed field is a
180
+
`uvicorn.Config` parameter and lands there under its own name.
181
+
182
+
Not typed, on purpose, because the runner pre-binds the socket and drives one `uvicorn.Server`
183
+
directly:
184
+
185
+
| Parameter | Why |
186
+
| --- | --- |
187
+
|`workers`| Read only by `uvicorn.run()`'s multiprocess supervisor. `Server.serve()` is single-process, so a `workers` in `uvicorn_kwargs` is stored on the config and never consulted: one process per pod, always |
0 commit comments