Content-Disposition
ResponseActiveContent-Disposition controls whether a response is displayed inline in the browser or downloaded as a file attachment. 'inline' (default) renders the content. 'attachment; filename="file.pdf"' triggers a download prompt. This is the header behind every browser file download – including API endpoints that export CSV, PDF, or ZIP files.
Description
Content-Disposition was originally defined for MIME email (RFC 2183) and adapted for HTTP (RFC 6266). In HTTP responses, 'attachment' causes the browser to download rather than render the response. The filename parameter provides the suggested save name. The filename* parameter (RFC 5987 encoding) supports non-ASCII filenames. Security: always sanitize the filename value – path traversal characters (../) in filename can cause issues on older clients.
Directives
| Directive | Description |
|---|---|
| inline | Default. Browser renders the content in the viewport. |
| attachment | Browser downloads the content as a file. |
| filename | Suggested filename for the download. ASCII only. |
| filename* | RFC 5987 encoded filename. Supports Unicode filenames. |
Examples
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="report-2025.pdf"Content-Disposition: attachment; filename*=UTF-8''%E5%A0%B1%E5%91%8A.pdfContent-Disposition: inline