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

@tinyhttp/res

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/res - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

dist/download.d.ts

8

CHANGELOG.md
# @tinyhttp/res
## 0.4.1
### Patch Changes
- Small bugfixes to @tinyhttp/send
- Updated dependencies [undefined]
- @tinyhttp/send@0.4.1
## 0.4.0

@@ -4,0 +12,0 @@

1

dist/index.d.ts

@@ -7,1 +7,2 @@ export * from '@tinyhttp/send';

export * from './redirect';
export * from './download';

@@ -0,1 +1,2 @@

import { sendFile } from '@tinyhttp/send';
export * from '@tinyhttp/send';

@@ -9,2 +10,4 @@ import { serialize } from '@tinyhttp/cookie';

import escapeHtml from 'escape-html';
import { contentDisposition } from '@tinyhttp/content-disposition';
import { resolve, extname } from 'path';

@@ -169,2 +172,47 @@ const setCookie = (req, res) => (name, value, options = {}) => {

export { clearCookie, formatResponse, getResponseHeader, redirect, setContentType, setCookie, setHeader, setLinksHeader, setLocationHeader, setVaryHeader };
const download = (req, res) => (path, filename, options, cb) => {
let done = cb;
let name = filename;
let opts = (options || null);
// support function as second or third arg
if (typeof filename === 'function') {
done = filename;
name = null;
opts = null;
}
else if (typeof options === 'function') {
done = options;
opts = null;
}
// set Content-Disposition when file is sent
const headers = {
'Content-Disposition': contentDisposition(name || path),
};
// merge user-provided headers
if (opts && opts.headers) {
for (const key of Object.keys(opts.headers)) {
if (key.toLowerCase() !== 'content-disposition') {
headers[key] = opts.headers[key];
}
}
}
// merge user-provided options
opts = Object.create(opts);
opts.headers = headers;
// Resolve the full path for sendFile
const fullPath = resolve(path);
const noop = () => {
return;
};
// send file
return sendFile(req, res)(fullPath, opts, done || noop);
};
const attachment = (req, res) => (filename) => {
if (filename) {
setContentType(req, res)(extname(filename));
}
setHeader(req, res)('Content-Disposition', contentDisposition(filename));
return res;
};
export { attachment, clearCookie, download, formatResponse, getResponseHeader, redirect, setContentType, setCookie, setHeader, setLinksHeader, setLocationHeader, setVaryHeader };

5

package.json
{
"name": "@tinyhttp/res",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",

@@ -40,6 +40,7 @@ "description": "response extensions for tinyhttp",

"dependencies": {
"@tinyhttp/content-disposition": "^0.4.0",
"@tinyhttp/cookie": "0.4.0",
"@tinyhttp/cookie-signature": "0.4.0",
"@tinyhttp/req": "0.4.0",
"@tinyhttp/send": "0.4.0",
"@tinyhttp/send": "0.4.1",
"es-mime-types": "^0.0.16",

@@ -46,0 +47,0 @@ "es-vary": "^0.0.7",

@@ -7,1 +7,2 @@ export * from '@tinyhttp/send'

export * from './redirect'
export * from './download'

Sorry, the diff of this file is not supported yet

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