res.type(type)
将 Content-Type
HTTP 标头设置为由指定 type
确定的 MIME 类型。如果 type
包含 "/" 字符,则它将 Content-Type
设置为 type
的确切值,否则假定它是文件扩展名并使用 express.static.mime.lookup()
方法在映射中查找 MIME 类型。
Sets the Content-Type
HTTP header to the MIME type as determined by the specified type
. If type
contains the "/" character, then it sets the Content-Type
to the exact value of type
, otherwise it is assumed to be a file extension and the MIME type is looked up in a mapping using the express.static.mime.lookup()
method.
res.type('.html') // => 'text/html'
res.type('html') // => 'text/html'
res.type('json') // => 'application/json'
res.type('application/json') // => 'application/json'
res.type('png') // => image/png: