# req.is

根据 "Content-Type" 和 type 判断,返回匹配的内容类型。

# 概要

req.is(type)

# 描述

如果传入请求的 "Content-Type" HTTP 标头字段与 type 参数指定的 MIME 类型匹配,则返回匹配的内容类型。如果请求没有正文,则返回 null。否则返回 false

// With Content-Type: text/html; charset=utf-8
req.is('html') // => 'html'
req.is('text/html') // => 'text/html'
req.is('text/*') // => 'text/*'

// When Content-Type is application/json
req.is('json') // => 'json'
req.is('application/json') // => 'application/json'
req.is('application/*') // => 'application/*'

req.is('html')
// => false

如需更多信息,或者如果您有问题或疑虑,请参阅 type-is

Last Updated: 3/22/2023, 7:27:28 PM