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

S3 adapter: upload with "content-type" and "content-encoding" headers #338

Open
HoneyryderChuck opened this issue Dec 19, 2019 · 1 comment

Comments

@HoneyryderChuck
Copy link

If I use the S3 adapter provided by the gem, after uploading the file ("sitemap.xml.gz"), when I provide the URL to a sitemap validator (like xml-sitemaps.com/validate-xml-sitemap.html ), there is an error, because the request returns an unexpected content media type: "application/gzip".

This happens because the raw S3 upload does not declare the media type, and this is inferred (either by S3 or fog). I've patched the adapter's write method locally so I could have access to the fog API that allows me to set these:

# lib/sitemap_generator/adapters/s3_adapter.rb#L30
  def write(location, raw_data)
      SitemapGenerator::FileAdapter.new.write(location, raw_data)

      directory.files.create(
        :key    => location.path_in_public,
        :body   => File.open(location.path),
        :public => true,
        "Content-Type" => "application/xml",
        "Content-Encoding" => "gzip"
      )
    end

After uploading with this patch, the sitemap link could be validated.

I'd like to propose either passing headers as a supported option, or to apply these changes to the adapter, depending of whether compression is on or off (for "content-encoding").

@marckohlbrugge
Copy link

I'm running into this same issue with Cloudflare R2 which uses the S3 adapter. My sitemap files have the application/x-gzip content-type which seems to confuse Google.

Would you mind making a PR of your suggested change? I think more people would benefit from it.

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

No branches or pull requests

2 participants