@tinyhttp/req
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -1,3 +0,3 @@ | ||
/// <reference types="node" /> | ||
import { IncomingMessage } from 'node:http'; | ||
type Request = Pick<IncomingMessage, 'headers'>; | ||
@@ -4,0 +4,0 @@ type AcceptReturns = string | boolean | string[]; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="node" /> | ||
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'node:http'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Check freshness of the response using request and response headers. |
@@ -1,11 +0,11 @@ | ||
/// <reference types="node" /> | ||
import { IncomingMessage as Request, ServerResponse as Response } from 'node:http'; | ||
import { Options, Ranges, Result } from 'header-range-parser'; | ||
export * from './accepts.js'; | ||
export * from '@tinyhttp/url'; | ||
export declare const getRequestHeader: (req: Pick<Request, 'headers'>) => (header: string) => string | string[]; | ||
export declare const getRangeFromHeader: (req: Pick<Request, 'headers'>) => (size: number, options?: Options) => Result | Ranges; | ||
export declare const getFreshOrStale: (req: Pick<Request, 'headers' | 'method'>, res: Pick<Response, 'getHeader' | 'statusCode'>) => boolean; | ||
export declare const checkIfXMLHttpRequest: (req: Pick<Request, 'headers'>) => boolean; | ||
export declare const reqIs: (req: Pick<Request, 'headers'>) => (...types: string[]) => string | false; | ||
export declare const getRequestHeader: (req: Pick<Request, "headers">) => (header: string) => string | string[]; | ||
export declare const getRangeFromHeader: (req: Pick<Request, "headers">) => (size: number, options?: Options) => Result | Ranges; | ||
export declare const getFreshOrStale: (req: Pick<Request, "headers" | "method">, res: Pick<Response, "getHeader" | "statusCode">) => boolean; | ||
export declare const checkIfXMLHttpRequest: (req: Pick<Request, "headers">) => boolean; | ||
export declare const reqIs: (req: Pick<Request, "headers">) => (...types: string[]) => string | false; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,8 +13,6 @@ import { parseRange } from "header-range-parser"; | ||
case 32: | ||
if (start === end) | ||
start = end = i + 1; | ||
if (start === end) start = end = i + 1; | ||
break; | ||
case 44: | ||
if (compareETags(etag, noneMatch.substring(start, end))) | ||
return false; | ||
if (compareETags(etag, noneMatch.substring(start, end))) return false; | ||
start = end = i + 1; | ||
@@ -27,4 +25,3 @@ break; | ||
} | ||
if (compareETags(etag, noneMatch.substring(start, end))) | ||
return false; | ||
if (compareETags(etag, noneMatch.substring(start, end))) return false; | ||
return true; | ||
@@ -35,16 +32,12 @@ } | ||
const noneMatch = reqHeaders["if-none-match"]; | ||
if (!modifiedSince && !noneMatch) | ||
return false; | ||
if (!modifiedSince && !noneMatch) return false; | ||
const cacheControl = reqHeaders["cache-control"]; | ||
if (cacheControl && CACHE_CONTROL_NO_CACHE_REGEXP.test(cacheControl)) | ||
return false; | ||
if (cacheControl && CACHE_CONTROL_NO_CACHE_REGEXP.test(cacheControl)) return false; | ||
if (noneMatch !== "*") { | ||
const etag = resHeaders.etag; | ||
if (!etag || isStale(etag, noneMatch)) | ||
return false; | ||
if (!etag || isStale(etag, noneMatch)) return false; | ||
} | ||
if (modifiedSince) { | ||
const lastModified = resHeaders["last-modified"]; | ||
if (!lastModified || !(Date.parse(lastModified) <= Date.parse(modifiedSince))) | ||
return false; | ||
if (!lastModified || !(Date.parse(lastModified) <= Date.parse(modifiedSince))) return false; | ||
} | ||
@@ -69,4 +62,3 @@ return true; | ||
const range = getRequestHeader(req)("Range"); | ||
if (!range) | ||
return; | ||
if (!range) return; | ||
return parseRange(size, range, options); | ||
@@ -77,4 +69,3 @@ }; | ||
const status = res.statusCode; | ||
if (method !== "GET" && method !== "HEAD") | ||
return false; | ||
if (method !== "GET" && method !== "HEAD") return false; | ||
if (status >= 200 && status < 300 || status === 304) { | ||
@@ -81,0 +72,0 @@ return fresh(req.headers, { |
{ | ||
"name": "@tinyhttp/req", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"type": "module", | ||
@@ -30,9 +30,6 @@ "description": "request extensions for tinyhttp", | ||
"header-range-parser": "^1.1.3", | ||
"@tinyhttp/accepts": "2.2.1", | ||
"@tinyhttp/url": "2.1.1", | ||
"@tinyhttp/type-is": "2.2.2" | ||
"@tinyhttp/accepts": "2.2.2", | ||
"@tinyhttp/type-is": "2.2.3", | ||
"@tinyhttp/url": "2.1.1" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
@@ -39,0 +36,0 @@ "dev": "vite", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
15341
12
112
+ Added@tinyhttp/accepts@2.2.2(transitive)
+ Added@tinyhttp/type-is@2.2.3(transitive)
- Removed@tinyhttp/accepts@2.2.1(transitive)
- Removed@tinyhttp/type-is@2.2.2(transitive)
Updated@tinyhttp/accepts@2.2.2
Updated@tinyhttp/type-is@2.2.3