CORS support for bareasgi
Project description
bareasgi-cors
CORS support for bareASGI (read the documentation)
Usage
A convenience function is provided.
import json
import logging
import uvicorn
from bareasgi import (
Application,
text_reader,
text_writer
)
from bareasgi_cors import CORSMiddleware
logging.basicConfig(level=logging.DEBUG)
async def get_info(scope, info, matches, content):
text = json.dumps(info)
return 200, [(b'content-type', b'application/json')], text_writer(text)
async def set_info(scope, info, matches, content):
text = await text_reader(content)
data = json.loads(text)
info.update(data)
return 204, None, None
cors_middleware = CORSMiddleware()
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-3.1.0.tar.gz
(8.1 kB
view hashes)
Built Distribution
Close
Hashes for bareasgi_cors-3.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f96462365d141eff8a06c7376442f7cbdb6cdd359aa874fa31f0fceb2d6dc9d9 |
|
MD5 | 8f107c9383ea6c41f76b9f69296a7cb2 |
|
BLAKE2b-256 | cb6a6c6302d4148bb6548eee9cb548af1da7974c0ca6a4555e8ffc3803379e73 |