On this page
A downloaded file’s name does not have to match the last part of its URL. If a download filename is different from the URL, the server’s Content-Disposition response header is often the reason—but redirects, browser settings, and operating-system behavior can also affect what you see. Here’s how to inspect the response and identify the source of the name.
Key Takeaways
- A URL path identifies a resource; it does not dictate the name used when saving it.
Content-Disposition: attachmentasks the browser to treat a response as a download, and itsfilenameparameter can suggest a name.filename*supports encoded names such as those containing non-ASCII characters. When both parameters are present, compatible clients should preferfilename*.- Inspect the actual response headers, including redirects, before concluding that a browser or operating system changed the name.
- Treat any suggested filename as untrusted input—not as a filesystem path.
The URL and the download name serve different purposes
A URL such as /download/8392 can identify a file without revealing its name. The server might look up that resource, generate its contents, or redirect to another URL. The final response can then suggest a friendly name for saving it.
For example, a response to https://example.test/download/8392 might include:
Content-Disposition: attachment; filename="annual-report.pdf"
The URL still ends in 8392, but the header suggests annual-report.pdf. The name is advice to the receiving client, not a change to the URL or the resource’s identity.
Content-Disposition can also indicate presentation behavior. attachment requests download-style handling; inline indicates that the response can be displayed as part of the page when the browser supports it. Browser preferences and the type of content can influence what happens in practice.
Advertisement
How filename and filename* work
The filename parameter is the traditional way to suggest a name. For greater compatibility, servers commonly use it as an ASCII fallback. The extended filename* parameter supports encoded characters, such as accented letters, using the format defined by RFC 8187.
A response can provide both:
Content-Disposition: attachment; filename="resume.pdf"; filename*=UTF-8''r%C3%A9sum%C3%A9.pdf
A client that understands filename* should use the extended value—in this example, résumé.pdf—rather than the fallback. The UTF-8'' prefix identifies the character encoding and an optional language field; the percent-encoded bytes represent the filename. Older clients might use only filename, which is why a plain ASCII fallback remains useful.
The header value is not a command to save to an arbitrary location. RFC 6266 advises recipients to treat the supplied name as advisory and to take care with path components and extensions. A browser may remove path information or adjust the suggested name to meet its own rules.
Inspect the response headers
Use a GET request to inspect the response that a download request actually receives:
curl -sS -D - -o /dev/null 'https://example.test/download/8392'
-D - prints response headers, and -o /dev/null discards the body. Look for Content-Disposition and note the status code. Replace the example URL with a resource you are authorized to access.
If the request redirects, inspect the redirect chain as well:
curl -sS -L -D - -o /dev/null 'https://example.test/download/8392'
With -L, curl follows redirects; -D - can show headers from multiple responses. Check which response contains the Content-Disposition header, especially the final response that supplies the file. A redirect can lead to a different host or endpoint whose response determines the suggested name.
A HEAD request, for example curl -I, can be useful for a quick check, but it is not always a reliable substitute for inspecting the GET used by the download. Servers or applications can handle HEAD differently. Compare against the browser’s actual request if the results disagree.
In browser developer tools, open the Network panel, reproduce the download, and inspect the request and its response headers. If the request redirects, examine each response and the final URL. Preserve the network log if navigating away would otherwise clear it.
Advertisement
Separate server behavior from browser and operating-system behavior
Use the observations to narrow down the cause:
| What you observe | Likely explanation |
|---|---|
The final response has a Content-Disposition filename that differs from the URL | The server or download service suggested a different name. |
| The response has no filename parameter | The browser may infer a name from the URL, content, or its own download behavior. |
| A redirect ends at a URL with a different response header | The destination response may be supplying the name. |
| The header’s name differs from the saved file’s name | The browser, user-selected save name, download settings, or operating system may have changed it. |
| The name is right but the extension or characters differ | Check the complete header value and how the browser or operating system handles it. |
The Content-Disposition header helps explain what the server suggested; it does not by itself prove how a particular browser or operating system will save the file. When debugging, record the complete response headers, redirect chain, browser, and the actual saved name. Avoid drawing conclusions from the URL alone.
Handle suggested filenames safely in your application
If your application generates a download response, build the header with a framework’s supported response or header API rather than concatenating untrusted input into raw header text. Incorrect handling can result in malformed headers or header injection.
If your application receives a filename from a user or an upstream service, treat it only as a display label. Do not join it to a storage directory or use it as the path to write a file. Generate a storage name or identifier separately, and apply your own filename policy when presenting a name to users. That policy should account for path separators, control characters, platform-reserved names, Unicode, length limits, and allowed extensions. Merely removing ../ or calling a basename function is not a complete validation strategy.
Common Mistakes
- Assuming the final URL path always determines the saved name.
- Checking only the first response when a download follows redirects.
- Treating
curl -Ias conclusive when the actual download uses GET. - Expecting every client to support
filename*or display international characters identically. - Assuming
Content-Dispositionguarantees the exact name or location on disk. - Using a suggested filename directly as a trusted filesystem path.
Best Practices
- Inspect the response headers for the actual download request and follow redirects when relevant.
- Use
filenameas a compatibility fallback andfilename*for international names when generating HTTP responses. - Keep server-side storage identifiers separate from user-facing download names.
- Sanitize and constrain untrusted names according to the requirements of the application and operating system.
- Test downloads in the browsers and environments your users rely on.
Conclusion
A download name can differ from a URL because the server can suggest a name in Content-Disposition, and redirects or client behavior can affect the final result. Inspect the actual response chain to find the source, and treat suggested filenames as untrusted labels rather than safe paths.
References
- RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) — describes the header’s disposition types, filename parameters, and recipient guidance.
- RFC 8187: Indicating Character Encoding and Language for HTTP Header Field Parameters — defines the encoding format used by extended parameters such as
filename*. - MDN: Content-Disposition — practical reference for the response header and its parameters.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.