Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support access-control-max-age header #12

Closed
simonw opened this issue Apr 8, 2024 · 1 comment
Closed

Support access-control-max-age header #12

simonw opened this issue Apr 8, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Apr 8, 2024

This header allows the client to remember the CORS result so it doesn't have to perform a pre-flight OPTIONS request before every POST etc.

access-control-max-age: 7200
@simonw simonw added the enhancement New feature or request label Apr 8, 2024
@simonw simonw closed this as completed in 2f99fd2 Apr 8, 2024
@simonw
Copy link
Owner Author

simonw commented Apr 8, 2024

I tested this - and the other features - with a tiny temporary plugin here running on Datasette Cloud: https://gist.github.com/simonw/59ccfeb2a9de09151d08df2b64336d03

from asgi_cors import asgi_cors
from datasette import hookimpl


@hookimpl
def asgi_wrapper(datasette):
    def wrap_with_asgi_cors(app):
        return asgi_cors(
            app,
            allow_all=True,
            methods=("GET", "POST", "OPTIONS"),
            headers=("authorization", "link", "content-type"),
            max_age=60
        )

    return wrap_with_asgi_cors

Here's a screenshot showing the 60s access-control-max-age working:

image

simonw added a commit that referenced this issue Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant