Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tinyhttp/req

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/req - npm Package Compare versions

Comparing version 2.0.13 to 2.0.14

vite.config.ts

75

dist/index.js

@@ -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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc