Skip to main content

A Quart extension to provide Cross Origin Resource Sharing, access control, support.

Project description

Build Status pypi python license

Quart-CORS is an extension for Quart to handle Cross Origin Resource Sharing, CORS (also known as access control).

CORS is required to share resources in browsers due to the Same Origin Policy which prevents resources being read and limits write actions from a different origin. An origin in this case is defined as the scheme, host and port combination.

In practice the Same Origin Policy means that a browser visiting http://quart.com will prevent the response of GET http://api.com being read. It will also prevent requests such as POST http://api.com. Note that embedding is allowed e.g. <img src="http://api.com/img.gif">.

CORS allows the server to indicate to the browser that certain resources can be used. It does so for GET requests by returning headers that indicate the origins that can use the resource whereas for other requests the browser will send a preflight OPTIONS request and then inspect the headers in the response.

Simple (GET) requests should return CORS headers specifying the allowed origins (which can be any origin, *) and whether credentials should be shared. If credentials can be shared the origins must be specific and not a wildcard.

Preflight requests should return CORS headers specifying the allowed origins, methods and headers in the request, whehter credentials should be shared and what response headers should be exposed.

Usage

To add CORS access control headers to all of the routes in the application, simply apply the cors function to the application,

app = Quart(__name__)
app = cors(app)

alternatively if you wish to add CORS selectively either apply the cors function to a blueprint or the route_cors function to a route,

blueprint = Blueprint(__name__)
blueprint = cors(blueprint)

@blueprint.route('/')
@route_cors()
async def handler():
    ...

In addition defaults can be specified in the application configuration,

Configuration key

type

QUART_CORS_ALLOW_CREDENTIALS

bool

QUART_CORS_ALLOW_HEADERS

Set[str]

QUART_CORS_ALLOW_METHODS

Set[str]

QUART_CORS_ALLOW_ORIGIN

Set[str]

QUART_CORS_EXPOSE_HEADERS

Set[str]

QUART_CORS_MAX_AGE

float

Both the cors and route_cors functions take these arguments,

Argument

type

allow_credentials

bool

allow_headers

Union[Set[str], str]

allow_methods

Union[Set[str], str]

allow_origin

Union[Set[str], str]

expose_headers

Union[Set[str], str]

max_age

Union[int, flot, timedelta]

Contributing

Quart-CORS is developed on GitLab. You are very welcome to open issues or propose merge requests.

Testing

The best way to test Quart-CORS is with Tox,

$ pipenv install tox
$ tox

this will check the code style and run the tests.

Help

This README is the best place to start, after that try opening an issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Quart-CORS-0.1.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

Quart_CORS-0.1.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file Quart-CORS-0.1.3.tar.gz.

File metadata

  • Download URL: Quart-CORS-0.1.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Quart-CORS-0.1.3.tar.gz
Algorithm Hash digest
SHA256 149604c950c7c839089c8ec4128df98e93130201c128a214630656d18fada42d
MD5 e25e8913918683e8a5b9388cbe8afcce
BLAKE2b-256 97dcb6d04e7c444302e18554eb1986805975a8d0fee7fc486da39e0b73b7c36f

See more details on using hashes here.

File details

Details for the file Quart_CORS-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: Quart_CORS-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Quart_CORS-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fb4766f9b3134e2f4d1c49c17d95d9a2b60965c0b53a06fbb798f92b0356e7d6
MD5 b1b514909e51620973324820a2f6bb9d
BLAKE2b-256 6f40808bfec481d8123865e1f55cec48126c4d03999386787f7b64b52294448f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page