@tinyhttp/res
Advanced tools
Comparing version
@@ -1,4 +0,3 @@ | ||
/// <reference types="node/http.js" /> | ||
/// <reference types="node" /> | ||
import { ServerResponse as Res } from 'node:http'; | ||
export declare const append: <Response_1 extends Res<import("http").IncomingMessage> = Res<import("http").IncomingMessage>>(res: Response_1) => (field: string, value: string | number | string[]) => Response_1; | ||
//# sourceMappingURL=append.d.ts.map |
@@ -9,2 +9,1 @@ import { IncomingMessage as Req, ServerResponse as Res } from 'node:http'; | ||
export declare const clearCookie: <Request_1 extends Req = Req, Response_1 extends Res<Req> = Res<Req>>(req: Request_1, res: Response_1) => (name: string, options?: cookie.SerializeOptions) => Response_1; | ||
//# sourceMappingURL=cookie.d.ts.map |
@@ -10,2 +10,1 @@ import { IncomingMessage as Req, ServerResponse as Res } from 'node:http'; | ||
export {}; | ||
//# sourceMappingURL=download.d.ts.map |
@@ -13,2 +13,1 @@ import { IncomingMessage as Req, ServerResponse as Res } from 'node:http'; | ||
export {}; | ||
//# sourceMappingURL=format.d.ts.map |
@@ -10,2 +10,1 @@ import { IncomingMessage as Req, ServerResponse as Res } from 'node:http'; | ||
export declare const setContentType: <Response_1 extends Res<Req> = Res<Req>>(res: Response_1) => (type: string) => Response_1; | ||
//# sourceMappingURL=headers.d.ts.map |
@@ -9,2 +9,1 @@ export * from '@tinyhttp/send'; | ||
export { append } from './append.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,5 +5,5 @@ import { sendFile } from "@tinyhttp/send"; | ||
import { sign } from "@tinyhttp/cookie-signature"; | ||
import * as mime from "es-mime-types"; | ||
import mime from "mime"; | ||
import { getRequestHeader, getAccepts } from "@tinyhttp/req"; | ||
import { vary } from "es-vary"; | ||
import { vary } from "@tinyhttp/vary"; | ||
import { encodeUrl } from "@tinyhttp/encode-url"; | ||
@@ -13,3 +13,3 @@ import { STATUS_CODES } from "node:http"; | ||
import { contentDisposition } from "@tinyhttp/content-disposition"; | ||
import { resolve, extname } from "node:path"; | ||
import { basename, resolve, extname } from "node:path"; | ||
const charsetRegExp = /;\s*charset\s*=/; | ||
@@ -24,5 +24,4 @@ const setHeader = (res) => (field, val) => { | ||
if (!charsetRegExp.test(value)) { | ||
const charset = mime.charset(value.split(";")[0]); | ||
if (typeof charset === "string") | ||
value += "; charset=" + charset.toLowerCase(); | ||
const charset = "UTF-8"; | ||
value += "; charset=" + charset.toLowerCase(); | ||
} | ||
@@ -63,3 +62,3 @@ } | ||
const setContentType = (res) => (type) => { | ||
const ct = type.indexOf("/") === -1 ? mime.lookup(type) : type; | ||
const ct = type.indexOf("/") === -1 ? mime.getType(type) : type; | ||
setHeader(res)("Content-Type", ct); | ||
@@ -97,3 +96,3 @@ return res; | ||
}; | ||
const normalizeType = (type) => ~type.indexOf("/") ? acceptParams(type) : { value: mime.lookup(type), params: {} }; | ||
const normalizeType = (type) => ~type.indexOf("/") ? acceptParams(type) : { value: mime.getType(type), params: {} }; | ||
function acceptParams(str, index) { | ||
@@ -179,3 +178,3 @@ const parts = str.split(/ *; */); | ||
const headers = { | ||
"Content-Disposition": contentDisposition(name || path) | ||
"Content-Disposition": contentDisposition(name || basename(path)) | ||
}; | ||
@@ -192,4 +191,6 @@ if (opts && opts.headers) { | ||
const attachment = (res) => (filename) => { | ||
if (filename) | ||
if (filename) { | ||
setContentType(res)(extname(filename)); | ||
filename = basename(filename); | ||
} | ||
setHeader(res)("Content-Disposition", contentDisposition(filename)); | ||
@@ -213,1 +214,2 @@ return res; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -5,2 +5,1 @@ import { IncomingMessage as Req, ServerResponse as Res } from 'node:http'; | ||
export {}; | ||
//# sourceMappingURL=redirect.d.ts.map |
@@ -10,2 +10,1 @@ export type NormalizedType = { | ||
export declare function normalizeTypes(types: string[]): NormalizedType[]; | ||
//# sourceMappingURL=util.d.ts.map |
{ | ||
"name": "@tinyhttp/res", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"type": "module", | ||
@@ -28,11 +28,11 @@ "description": "response extensions for tinyhttp", | ||
"dependencies": { | ||
"@tinyhttp/vary": "^0.1.3", | ||
"es-escape-html": "^0.1.1", | ||
"es-mime-types": "^0.1.4", | ||
"es-vary": "^0.1.2", | ||
"@tinyhttp/content-disposition": "2.1.0", | ||
"mime": "4.0.0-beta.1", | ||
"@tinyhttp/content-disposition": "2.2.0", | ||
"@tinyhttp/cookie": "2.1.0", | ||
"@tinyhttp/cookie-signature": "2.1.0", | ||
"@tinyhttp/req": "2.2.0", | ||
"@tinyhttp/encode-url": "2.1.0", | ||
"@tinyhttp/req": "2.1.0", | ||
"@tinyhttp/send": "2.1.0" | ||
"@tinyhttp/send": "2.2.0" | ||
}, | ||
@@ -39,0 +39,0 @@ "scripts": { |
272
0.74%28214
-28.92%14
-36.36%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated