Skip to content

Add CORS headers to simple API#13222

Merged
di merged 5 commits intopypi:mainfrom
ryanking13:simple-cors
Mar 23, 2023
Merged

Add CORS headers to simple API#13222
di merged 5 commits intopypi:mainfrom
ryanking13:simple-cors

Conversation

@ryanking13
Copy link
Copy Markdown
Contributor

Hello from Pyodide!

This adds CORS headers to simple API to allow fetching responses from client-side JavaScript.

Additional context

Pyodide has a runtime in-browser package manager called micropip, which downloads packages from PyPI. So far, Pyodide was using the legacy pypi.org/pypi/<name>/json endpoint to fetch package metadata, but we are considering migrating to pypi.org/simple/. The legacy API sets CORS headers (#578), while simple API doesn't.

Related:

@ryanking13 ryanking13 requested a review from a team as a code owner March 17, 2023 06:57
@di di merged commit 4271f2e into pypi:main Mar 23, 2023
@di
Copy link
Copy Markdown
Member

di commented Mar 23, 2023

Thanks! Good luck with Pyodide, definitely let us know if you need anything else!

@ryanking13 ryanking13 deleted the simple-cors branch March 23, 2023 22:53
@ryanking13
Copy link
Copy Markdown
Contributor Author

@di Hi, it seems that packages that have been cached before this PR don't have this header yet. Is there a regular period when PyPI flushes the cache?

For example, pyperformance (https://pypi.org/simple/pyperformance) has CORS headers:

$ curl -v https://pypi.org/simple/pyperformance/ 2>&1 | grep access-control
< access-control-allow-headers: Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since
< access-control-allow-methods: GET
< access-control-allow-origin: *
< access-control-expose-headers: X-PyPI-Last-Serial
< access-control-max-age: 86400

while, snowballstemmer (https://pypi.org/simple/snowballstemmer/) doesn't:

$ curl -v https://pypi.org/simple/snowballstemmer/ 2>&1 | grep access-control
[no headers]

@di
Copy link
Copy Markdown
Member

di commented Apr 19, 2023

I manually purged the cache for this one and the headers are now present:

$ curl -v https://pypi.org/simple/snowballstemmer/ 2>&1 | grep access-control
< access-control-allow-headers: Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since
< access-control-allow-methods: GET
< access-control-allow-origin: *
< access-control-expose-headers: X-PyPI-Last-Serial
< access-control-max-age: 86400

I'm not sure why our CDN was serving a stale page here, but this is likely related to #12214.

If you have other examples, I can purge them as well.

@ryanking13
Copy link
Copy Markdown
Contributor Author

Thanks! I didn't realize that there was an existing issue about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants