Metadata-Version: 2.4
Name: bareasgi-cors
Version: 5.0.0
Summary: CORS support for bareasgi
Author-email: Rob Blackbourn <rob.blackbourn@gmail.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://bareASGI.github.io/bareASGI-cors
Project-URL: Repository, https://github.com/bareASGI/bareASGI-cors
Project-URL: Issues, https://github.com/bareASGI/bareASGI-cors/issues
Keywords: asgi,web,framework,asyncio,http,cors
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: bareASGI<6,>=5.0.0
Provides-Extra: dev
Requires-Dist: autopep8; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pylint; extra == "dev"
Requires-Dist: types-setuptools; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs; extra == "docs"
Requires-Dist: mkdocs-material; extra == "docs"
Requires-Dist: jetblack-markdown; extra == "docs"
Requires-Dist: mike; extra == "docs"
Provides-Extra: examples
Requires-Dist: hypercorn; extra == "examples"
Requires-Dist: uvicorn; extra == "examples"
Dynamic: license-file

# bareASGI-cors

CORS support for [bareASGI](http://github.com/bareASGI/bareASGI) (read the
[docs](https://bareASGI.github.io/bareASGI-cors/))

## Usage

Simply create the `CORSMiddleware` class and put is as the first middleware.

```python
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.
