使用 Content-Disposition 元数据

为了覆盖浏览器的默认行为,可以使用 Content-Disposition 头来指定覆盖行为,并将此头赋值给一个对象。例如,此头可以指定浏览器使用下载程序来保存此文件,而不是显示该文件,这是默认行为。

示例:覆盖浏览器默认行为的 HTTP 请求:

此示例将附件类型分配给 Content-Disposition 头。此附件类型指示文件应作为 goodbye.txt 下载。

# curl -i  $publicURL/marktwain/goodbye -X POST -H "X-Auth-Token: $token" -H "Content-Length: 14" -H "Content-Type: application/octet-stream" -H "Content-Disposition: attachment; filename=goodbye.txt"
HTTP/1.1 202 Accepted
Content-Length: 76
Content-Type: text/html; charset=UTF-8
X-Trans-Id: txa9b5e57d7f354d7ea9f57-0052e17e13
X-Openstack-Request-Id: txa9b5e57d7f354d7ea9f57-0052e17e13
Date: Thu, 23 Jan 2014 20:39:47 GMT

<html><h1>Accepted</h1><p>The request is accepted for processing.</p></html>