API inicial
This commit is contained in:
8
node_modules/helmet/dist/middlewares/expect-ct/index.d.ts
generated
vendored
Normal file
8
node_modules/helmet/dist/middlewares/expect-ct/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { IncomingMessage, ServerResponse } from "http"
|
||||
export interface ExpectCtOptions {
|
||||
maxAge?: number
|
||||
enforce?: boolean
|
||||
reportUri?: string
|
||||
}
|
||||
declare function expectCt(options?: Readonly<ExpectCtOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
|
||||
export default expectCt
|
||||
28
node_modules/helmet/dist/middlewares/expect-ct/index.js
generated
vendored
Normal file
28
node_modules/helmet/dist/middlewares/expect-ct/index.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict"
|
||||
Object.defineProperty(exports, "__esModule", { value: true })
|
||||
function parseMaxAge(value = 0) {
|
||||
if (value >= 0 && Number.isFinite(value)) {
|
||||
return Math.floor(value)
|
||||
} else {
|
||||
throw new Error(`Expect-CT: ${JSON.stringify(value)} is not a valid value for maxAge. Please choose a positive integer.`)
|
||||
}
|
||||
}
|
||||
function getHeaderValueFromOptions(options) {
|
||||
const directives = [`max-age=${parseMaxAge(options.maxAge)}`]
|
||||
if (options.enforce) {
|
||||
directives.push("enforce")
|
||||
}
|
||||
if (options.reportUri) {
|
||||
directives.push(`report-uri="${options.reportUri}"`)
|
||||
}
|
||||
return directives.join(", ")
|
||||
}
|
||||
function expectCt(options = {}) {
|
||||
const headerValue = getHeaderValueFromOptions(options)
|
||||
return function expectCtMiddleware(_req, res, next) {
|
||||
res.setHeader("Expect-CT", headerValue)
|
||||
next()
|
||||
}
|
||||
}
|
||||
module.exports = expectCt
|
||||
exports.default = expectCt
|
||||
Reference in New Issue
Block a user