Skip to content

feat(storage-*): include modified headers into the response headers of files when using adapters #12096

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

paulpopus
Copy link
Contributor

@paulpopus paulpopus commented Apr 12, 2025

This PR makes it so that modifyResponseHeaders is supported in our adapters when set on the collection config. Previously it would be ignored.

This means that users can now modify or append new headers to what's returned by each service.

import type { CollectionConfig } from 'payload'

export const Media: CollectionConfig = {
  slug: 'media',
  upload: {
    modifyResponseHeaders: ({ headers }) => {
      const newHeaders = new Headers(headers) // Copy existing headers
      newHeaders.set('X-Frame-Options', 'DENY') // Set new header

      return newHeaders
    },
  },
}

Also adds support for void return on the modifyResponseHeaders function in the case where the user just wants to use existing headers and doesn't need more control.

eg:

import type { CollectionConfig } from 'payload'

export const Media: CollectionConfig = {
  slug: 'media',
  upload: {
    modifyResponseHeaders: ({ headers }) => {
      headers.set('X-Frame-Options', 'DENY') // You can directly set headers without returning
    },
  },
}

TODO TESTING:

  • GCS
  • S3
  • Azure
  • UploadThing
  • Vercel Blob

@paulpopus paulpopus changed the title feat(storage*): include modified headers into the response headers of files when using adapters feat(storage-*): include modified headers into the response headers of files when using adapters Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants