@tinyhttp/app
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -8,2 +8,3 @@ /// <reference types="node" /> | ||
networkExtensions: boolean; | ||
freshnessTesting: boolean; | ||
}>; | ||
@@ -10,0 +11,0 @@ export declare class App extends Router { |
import { Request } from './request'; | ||
import { Response } from './response'; | ||
import { AppSettings } from './app'; | ||
export declare const extendMiddleware: ({ networkExtensions }: AppSettings) => (req: Request, res: Response) => void; | ||
export declare const extendMiddleware: ({ networkExtensions, freshnessTesting, }: AppSettings) => (req: Request, res: Response) => void; |
@@ -7,2 +7,3 @@ import { STATUS_CODES, METHODS, createServer } from 'http'; | ||
import Accepts from 'es-accepts'; | ||
import fresh from 'es-fresh'; | ||
import { sign } from '@tinyhttp/cookie-signature'; | ||
@@ -115,21 +116,18 @@ import { lookup } from 'es-mime-types'; | ||
// } | ||
/* export const getFreshOrStale = (req: Request, res: Response) => { | ||
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) || 304 === status) { | ||
const resHeaders = { | ||
etag: res.get('ETag'), | ||
'last-modified': res.get('Last-Modified'), | ||
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) || 304 === status) { | ||
const resHeaders = { | ||
etag: res.get('ETag'), | ||
'last-modified': res.get('Last-Modified'), | ||
}; | ||
return fresh(req.headers, resHeaders); | ||
} | ||
return fresh(req.headers, resHeaders) | ||
} | ||
return false | ||
} */ | ||
return false; | ||
}; | ||
const getAccepts = (req) => (...types) => { | ||
@@ -412,3 +410,3 @@ return new Accepts(req).types(types); | ||
const extendMiddleware = ({ networkExtensions }) => (req, res) => { | ||
const extendMiddleware = ({ networkExtensions, freshnessTesting, }) => (req, res) => { | ||
/// Define extensions | ||
@@ -430,5 +428,6 @@ res.get = getResponseHeader(req, res); | ||
req.query = getQueryParams(req.url); | ||
/* req.fresh = getFreshOrStale(req, res) | ||
req.stale = !req.fresh */ | ||
if (freshnessTesting) { | ||
req.fresh = getFreshOrStale(req, res); | ||
req.stale = !req.fresh; | ||
} | ||
req.get = getRequestHeader(req); | ||
@@ -538,2 +537,2 @@ req.set = setRequestHeader(req); | ||
export { App, Router, applyHandler, checkIfXMLHttpRequest, clearCookie, extendMiddleware, getAccepts, getHostname, getIP, getProtocol, getQueryParams, getRangeFromHeader, getRequestHeader, getResponseHeader, getRouteFromApp, getURLParams, json, send, sendStatus, setCookie, setHeader, setLinksHeader, setLocationHeader, setRequestHeader, status }; | ||
export { App, Router, applyHandler, checkIfXMLHttpRequest, clearCookie, extendMiddleware, getAccepts, getFreshOrStale, getHostname, getIP, getProtocol, getQueryParams, getRangeFromHeader, getRequestHeader, getResponseHeader, getRouteFromApp, getURLParams, json, send, sendStatus, setCookie, setHeader, setLinksHeader, setLocationHeader, setRequestHeader, status }; |
@@ -7,2 +7,3 @@ /// <reference types="node" /> | ||
import { Middleware, Handler } from './router'; | ||
import { Response } from './response'; | ||
export declare const getQueryParams: (url?: string) => ParsedUrlQuery; | ||
@@ -21,2 +22,3 @@ export declare type URLParams = { | ||
export declare const getIP: (req: Request) => string; | ||
export declare const getFreshOrStale: (req: Request, res: Response) => boolean; | ||
export declare const getAccepts: (req: Request) => (...types: string[]) => string | false | string[]; | ||
@@ -43,3 +45,5 @@ export declare type Connection = IncomingMessage['socket'] & { | ||
secret?: string | string[]; | ||
fresh?: boolean; | ||
stale?: boolean; | ||
body?: any; | ||
} |
{ | ||
"name": "@tinyhttp/app", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "tinyhttp core", | ||
@@ -42,5 +42,6 @@ "type": "module", | ||
"@tinyhttp/etag": "0.2.0", | ||
"es-accepts": "^0.0.11", | ||
"es-content-type": "^0.0.4", | ||
"es-mime-types": "^0.0.6", | ||
"es-accepts": "^0.0.12", | ||
"es-content-type": "^0.0.5", | ||
"es-fresh": "^0.0.3", | ||
"es-mime-types": "^0.0.7", | ||
"proxy-addr": "^2.0.6", | ||
@@ -47,0 +48,0 @@ "range-parser": "^1.2.1", |
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
47478
1227
10
+ Addedes-fresh@^0.0.3
+ Addedes-content-type@0.0.5(transitive)
+ Addedes-fresh@0.0.3(transitive)
+ Addedes-mime-types@0.0.7(transitive)
- Removedes-content-type@0.0.4(transitive)
- Removedes-mime-types@0.0.6(transitive)
Updatedes-accepts@^0.0.12
Updatedes-content-type@^0.0.5
Updatedes-mime-types@^0.0.7