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
Copy file name to clipboardExpand all lines: README.md
+32-24Lines changed: 32 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ WebSpark provides a simple yet powerful architecture for handling HTTP requests
18
18
-**Optimized JSON Handling**: Automatically uses the fastest available JSON library (`orjson`, `ujson`, or `json`).
19
19
-**Built-in File Uploads**: Seamlessly handle multipart form data and file uploads.
20
20
-**Comprehensive Error Handling**: A simple `HTTPException` system for clear and consistent error responses.
21
-
-**Security Features**: Built-in protection against HTTP Host header attacks and proxy support.
21
+
-**Proxy Support**: Built-in support for running behind a reverse proxy.
22
22
-**Environment Configuration**: Helper utilities for managing configuration via environment variables.
23
23
-**Extensive Testing**: 90% test coverage ensuring reliability and stability.
24
24
@@ -271,7 +271,7 @@ app.add_paths([
271
271
WebSpark includes a CORS (Cross-Origin Resource Sharing) plugin that implements the full CORS specification. It supports both simple and preflighted requests with configurable origins, methods, headers, and credentials.
272
272
273
273
```python
274
-
from webspark.contrib import CORSPlugin
274
+
from webspark.contrib.pluginsimport CORSPlugin
275
275
276
276
# Create a CORS plugin with a specific configuration
277
277
cors_plugin = CORSPlugin(
@@ -302,6 +302,29 @@ The CORS plugin supports the following configuration options:
302
302
-`expose_headers` - List of headers that browsers are allowed to access.
303
303
-`vary_header` - Whether to add Vary header for preflight requests.
304
304
305
+
#### AllowedHosts Plugin
306
+
307
+
To prevent HTTP Host header attacks, WebSpark provides an `AllowedHostsPlugin`. This plugin checks the request's `Host` header against a list of allowed hostnames.
308
+
309
+
```python
310
+
from webspark.contrib.plugins import AllowedHostsPlugin
311
+
312
+
# Allow requests only to "mydomain.com" and any subdomain of "api.mydomain.com"
- If `allowed_hosts` is not set, all requests will be rejected with a `400 Bad Request` error, ensuring that only requests from specified hosts are processed.
323
+
-**Matching**:
324
+
-`"mydomain.com"`: Matches the exact domain.
325
+
-`".mydomain.com"`: Matches `mydomain.com` and any subdomain (e.g., `api.mydomain.com`).
326
+
-`"*"`: Matches any host.
327
+
305
328
### 7. Error Handling
306
329
307
330
Gracefully handle errors using `HTTPException`. When raised, the framework will catch it and generate a standardized JSON error response.
@@ -372,27 +395,7 @@ The framework checks for the following headers when `TRUST_PROXY` is enabled:
372
395
-`X-Forwarded-Proto` for the request scheme (`http` or `https`).
373
396
-`X-Forwarded-Host` for the original host.
374
397
375
-
### 10. Allowed Hosts
376
-
377
-
To prevent HTTP Host header attacks, WebSpark checks the request's `Host` header against a list of allowed hostnames. This is configured via the `ALLOWED_HOSTS` setting on the configuration object.
378
-
379
-
```python
380
-
classAppConfig:
381
-
# Allow requests only to "mydomain.com" and any subdomain of "api.mydomain.com"
This helper streamlines configuration management, making it easy to handle different data types and required settings.
413
416
414
-
### 12. File Uploads
417
+
### 11. File Uploads
415
418
416
419
WebSpark makes handling file uploads simple with built-in multipart form data parsing. Uploaded files are accessible through the `ctx.files` attribute.
0 commit comments