publicsuffix / list

The Public Suffix List
https://publicsuffix.org/
Mozilla Public License 2.0
1.97k stars 1.2k forks source link

Cache-Control Header Results In "CORs Missing Allow Header" #1961

Closed rwilliams3088 closed 4 months ago

rwilliams3088 commented 4 months ago

I want to use the Public Suffix List on my front-end to parse hostnames and properly determine what the subdomains are in a generic but robust fashion. I also want to respect the request to not overload the server with GET requests, but to restrict the requests to every 24 hours or so.

However, if I attempt to set the Cache-control header to max-age=86400 then I get a CORs error; it would seem that the Cache-Control header is not permitted. If I remove this header, then Firefox uses the "no-cache" option instead....

const response = await fetch("https://publicsuffix.org/list/public_suffix_list.dat", {
      method: "GET",
      cache: reload ? "reload" : "default",
      headers: {
        "Cache-control": "max-age=86400"
      }
});

I'm thinking long-term I'll use my server to cache a copy of the file and then have the front-end request it from my server rather than directly from https://publicsuffix.org/list/public_suffix_list.dat. However, I wanted to bring your attention to it in case you want to fix it, or else if you can provide guidance on how to request the file via javascript with caching.

simon-friedberger commented 4 months ago

Maybe just use cache: default and let the browser figure it out. The list is already returned with cache-control: public,max-age=86400. I'm not entirely sure, but I don't think using the request header works. If you're making the request you are downloading a new list anyway. It might just affect caches on the way.

rwilliams3088 commented 4 months ago

Upon re-testing, removing the Cache-Control Header, it does look like the browser is properly caching the document and loading from the cache for subsequent GET requests :) Not sure what I was doing wrong previously - because it didn't look like it was caching then.. but looks like its all working as expected. Thanks!