Skip to content

Express request.is

TIP

Range 标头解析器。

Express
req.range(size[, options])
  • Range 标头解析器。
  • size 参数是资源的最大大小。
  • options 参数是一个可以具有以下属性的对象。
  • combine 指定是否应合并重叠和相邻范围,默认为 false。当 true 时,范围将被组合并返回,就好像它们在标题中以这种方式指定一样。
将返回一个范围数组或指示解析错误的负数。

-2表示格式错误的标头字符串 -1表示无法满足的范围

Express
// parse header from request
const range = req.range(1000)

// the type of the range
if (range.type === 'bytes') {
  // the ranges
  range.forEach((r) => {
    // do something with r.start and r.end
  })
}