Skip to content

Commit c9ea24a

Browse files
Update remotes.md (#34)
1 parent ad18478 commit c9ea24a

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

blacksheep/docs/remotes.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,30 @@ HTTP), we simply need to instruct the web application to generate URLs to itself
3939
/// tab | Since version 2.4.4
4040

4141
Since version `2.4.4`, the framework includes built-in features to force the HTTP scheme
42-
of generated URLs.
43-
44-
TODO: document env variables.
42+
of generated URLs. You can configure an environment variable to enforce the request's
43+
scheme property globally: `APP_FORCE_HTTPS=true` to force HTTPS and HSTS, or
44+
`APP_HTTP_SCHEME=https` to force `https`, or `APP_HTTP_SCHEME=http` to force `http`.
4545

4646
///
4747

4848
/// tab | Before version 2.4.4
4949

5050
Before `2.4.4`, the framework did not include any specific code to force the HTTP scheme
51-
and it required applying a middleware.
51+
and it required applying a middleware, setting the `request.scheme` early in the handler
52+
chain. For example:
5253

53-
TODO: like in FinOps API.
54+
```python {hl_lines="5-7"}
55+
def configure_http_scheme_middleware(app: Application):
56+
http_scheme_env = os.environ.get("APP_HTTP_SCHEME")
5457

55-
```python
58+
if http_scheme_env:
59+
async def http_scheme_middleware(request, next_handler):
60+
request.scheme = http_scheme_env
61+
return await next_handler(request)
5662

63+
@app.on_middlewares_configuration
64+
def on_middlewares_configuration(_):
65+
app.middlewares.insert(0, http_scheme_middleware)
5766
```
5867

5968
///
@@ -98,12 +107,12 @@ def configure_forwarded_headers(app):
98107

99108
Options of the `XForwardedHeadersMiddleware` class:
100109

101-
| Parameter | Type, default | Description |
102-
| -------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103-
| allowed_hosts | `Sequence[str] | None` = None | Sequence of allowed hosts. If configured, requests that send a different host in the `Host` header or `X-Forwarded-Host` header are replied with Bad Request. |
110+
| Parameter | Type, default | Description |
111+
| -------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
112+
| allowed_hosts | `Sequence[str] | None` = None | Sequence of allowed hosts. If configured, requests that send a different host in the `Host` header or `X-Forwarded-Host` header are replied with Bad Request. |
104113
| known_proxies | Sequence[IPAddress] | None = None | Sequence of allowed proxies IP addresses. If configured, requests that send different proxies IPs in the request scope or `X-Forwarded-For` header are replied with Bad Request. |
105114
| known_networks | Sequence[IPNetwork] | None = None | Sequence of allowed proxies networks. If configured, requests that send a foreign proxy IP in the request scope or `X-Forwarded-For` header are replied with Bad Request. |
106-
| forward_limit | int = 1 | Maximum number of allowed forwards, by default 1. |
115+
| forward_limit | int = 1 | Maximum number of allowed forwards, by default 1. |
107116

108117
When `known_proxies` is not provided, it is set by default to handle `localhost`:
109118
`[ip_address("127.0.0.1")]`.
@@ -134,12 +143,12 @@ def configure_forwarded_headers(app):
134143

135144
Options of the `ForwardedHeadersMiddleware` class:
136145

137-
| Parameter | Type, default | Description |
138-
| -------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
146+
| Parameter | Type, default | Description |
147+
| -------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
139148
| allowed_hosts | Sequence[str] | None = None | Sequence of allowed hosts. If configured, requests that send a different host in the `Host` header or `Forwarded` header are replied with Bad Request. |
140149
| known_proxies | Sequence[IPAddress] | None = None | Sequence of allowed proxies IP addresses. If configured, requests that send different proxies IPs in the request scope or `Forwarded` header are replied with Bad Request. |
141150
| known_networks | Sequence[IPNetwork] | None = None | Sequence of allowed proxies networks. If configured, requests that send a foreign proxy IP in the request scope or `Forwarded` header are replied with Bad Request. |
142-
| forward_limit | int = 1 | Maximum number of allowed forwards, by default 1. |
151+
| forward_limit | int = 1 | Maximum number of allowed forwards, by default 1. |
143152

144153
When `known_proxies` is not provided, it is set by default to handle `localhost`:
145154
`[ip_address("127.0.0.1")]`.

0 commit comments

Comments
 (0)