CORS support for bareasgi
Project description
bareASGI-cors
CORS support for bareASGI (read the docs)
Usage
Simply create the CORSMiddleware
class and put is as the first middleware.
import json
import uvicorn
from bareasgi import (
Application,
text_reader,
text_writer
)
from bareasgi_cors import CORSMiddleware
async def get_info(request):
text = json.dumps(request.info)
return HttpResponse(200, [(b'content-type', b'application/json')], text_writer(text))
async def set_info(request):
text = await text_reader(request.body)
data = json.loads(text)
request.info.update(data)
return HttpResponse(204)
# Create the CORS middleware class
cors_middleware = CORSMiddleware()
# Use the CORS middleware as the first middleware.
app = Application(info={'name': 'Michael Caine'}, middlewares=[cors_middleware])
app.http_router.add({'GET'}, '/info', get_info)
app.http_router.add({'POST', 'OPTIONS'}, '/info', set_info)
uvicorn.run(app, port=9010)
The POST method
In the above example an OPTION method is included with the POST. This is always required with a POST as a browser will try first with an OPTION.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bareasgi-cors-4.1.0.tar.gz
(8.5 kB
view details)
Built Distribution
File details
Details for the file bareasgi-cors-4.1.0.tar.gz
.
File metadata
- Download URL: bareasgi-cors-4.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.8.10 Linux/5.4.0-88-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d44e241cb1ce0d387047e3909c0a3301a04e3aa39fa5f7bf4f9799d4d5bb769 |
|
MD5 | ae2a768f15efa78c1b9dd8b47fe7ede3 |
|
BLAKE2b-256 | 1f8a192679a43c9d94af9b0baffef62d0de55a6db5e75b7e57791b337c1aa951 |
File details
Details for the file bareasgi_cors-4.1.0-py3-none-any.whl
.
File metadata
- Download URL: bareasgi_cors-4.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.8.10 Linux/5.4.0-88-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 176f8e20b5323a28338423a7665dae56b89a240d88894752174c0cba29f8c4bf |
|
MD5 | 2d322ddcfe46d8053afca255d82472b6 |
|
BLAKE2b-256 | 2c31d81ddf974917053b1d5ce33a7585b1e69dbed8d8b1eead5387c42f8c011d |