@tinyhttp/req
Advanced tools
Comparing version 2.0.13 to 2.0.14
@@ -1,7 +0,6 @@ | ||
import { parseRange } from 'header-range-parser'; | ||
import { fresh } from 'es-fresh'; | ||
import { typeIs } from '@tinyhttp/type-is'; | ||
import { Accepts } from '@tinyhttp/accepts'; | ||
export * from '@tinyhttp/url'; | ||
import { parseRange } from "header-range-parser"; | ||
import { fresh } from "es-fresh"; | ||
import { typeIs } from "@tinyhttp/type-is"; | ||
import { Accepts } from "@tinyhttp/accepts"; | ||
export * from "@tinyhttp/url"; | ||
const getAccepts = (req) => (...types) => new Accepts(req).types(types); | ||
@@ -11,37 +10,43 @@ const getAcceptsEncodings = (req) => (...encodings) => new Accepts(req).encodings(encodings); | ||
const getAcceptsLanguages = (req) => (...languages) => new Accepts(req).languages(languages); | ||
const getRequestHeader = (req) => (header) => { | ||
const lc = header.toLowerCase(); | ||
switch (lc) { | ||
case 'referer': | ||
case 'referrer': | ||
return req.headers.referrer || req.headers.referer; | ||
default: | ||
return req.headers[lc]; | ||
} | ||
const lc = header.toLowerCase(); | ||
switch (lc) { | ||
case "referer": | ||
case "referrer": | ||
return req.headers.referrer || req.headers.referer; | ||
default: | ||
return req.headers[lc]; | ||
} | ||
}; | ||
const getRangeFromHeader = (req) => (size, options) => { | ||
const range = getRequestHeader(req)('Range'); | ||
if (!range) | ||
return; | ||
return parseRange(size, range, options); | ||
const range = getRequestHeader(req)("Range"); | ||
if (!range) | ||
return; | ||
return parseRange(size, range, options); | ||
}; | ||
const getFreshOrStale = (req, res) => { | ||
const method = req.method; | ||
const status = res.statusCode; | ||
// GET or HEAD for weak freshness validation only | ||
if (method !== 'GET' && method !== 'HEAD') | ||
return false; | ||
// 2xx or 304 as per rfc2616 14.26 | ||
if ((status >= 200 && status < 300) || status === 304) { | ||
return fresh(req.headers, { | ||
etag: res.getHeader('ETag'), | ||
'last-modified': res.getHeader('Last-Modified') | ||
}); | ||
} | ||
const method = req.method; | ||
const status = res.statusCode; | ||
if (method !== "GET" && method !== "HEAD") | ||
return false; | ||
if (status >= 200 && status < 300 || status === 304) { | ||
return fresh(req.headers, { | ||
etag: res.getHeader("ETag"), | ||
"last-modified": res.getHeader("Last-Modified") | ||
}); | ||
} | ||
return false; | ||
}; | ||
const checkIfXMLHttpRequest = (req) => req.headers['X-Requested-With'] === 'XMLHttpRequest'; | ||
const reqIs = (req) => (...types) => typeIs(req.headers['content-type'], ...types); | ||
export { checkIfXMLHttpRequest, getAccepts, getAcceptsCharsets, getAcceptsEncodings, getAcceptsLanguages, getFreshOrStale, getRangeFromHeader, getRequestHeader, reqIs }; | ||
const checkIfXMLHttpRequest = (req) => req.headers["X-Requested-With"] === "XMLHttpRequest"; | ||
const reqIs = (req) => (...types) => typeIs(req.headers["content-type"], ...types); | ||
export { | ||
checkIfXMLHttpRequest, | ||
getAccepts, | ||
getAcceptsCharsets, | ||
getAcceptsEncodings, | ||
getAcceptsLanguages, | ||
getFreshOrStale, | ||
getRangeFromHeader, | ||
getRequestHeader, | ||
reqIs | ||
}; |
{ | ||
"name": "@tinyhttp/req", | ||
"version": "2.0.13", | ||
"version": "2.0.14", | ||
"type": "module", | ||
@@ -29,5 +29,5 @@ "description": "request extensions for tinyhttp", | ||
"dependencies": { | ||
"@tinyhttp/accepts": "2.0.6", | ||
"@tinyhttp/type-is": "2.0.5", | ||
"@tinyhttp/url": "2.0.6", | ||
"@tinyhttp/accepts": "2.0.7", | ||
"@tinyhttp/type-is": "2.0.6", | ||
"@tinyhttp/url": "2.0.7", | ||
"es-fresh": "^0.0.10", | ||
@@ -37,4 +37,6 @@ "header-range-parser": "^1.1.3" | ||
"scripts": { | ||
"build": "rollup -c ./rollup.config.js" | ||
"dev": "vite", | ||
"build": "vite build", | ||
"postbuild": "tsc --emitDeclarationOnly" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5753
7
72
+ Added@tinyhttp/accepts@2.0.7(transitive)
+ Added@tinyhttp/type-is@2.0.6(transitive)
+ Added@tinyhttp/url@2.0.7(transitive)
- Removed@tinyhttp/accepts@2.0.6(transitive)
- Removed@tinyhttp/type-is@2.0.5(transitive)
- Removed@tinyhttp/url@2.0.6(transitive)
Updated@tinyhttp/accepts@2.0.7
Updated@tinyhttp/type-is@2.0.6
Updated@tinyhttp/url@2.0.7