Socket
Socket
Sign inDemoInstall

fastify

Package Overview
Dependencies
Maintainers
4
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify - npm Package Compare versions

Comparing version 4.27.0 to 4.28.0

.tap/processinfo/029eb7a1-1942-40bc-98e2-cef3b7a14b5e.json

12

docs/Reference/Reply.md

@@ -20,3 +20,3 @@ <h1 align="center">Fastify</h1>

- [.removeTrailer(key)](#removetrailerkey)
- [.redirect([code ,] dest)](#redirectcode--dest)
- [.redirect(dest, [code ,])](#redirectdest--code)
- [.callNotFound()](#callnotfound)

@@ -66,4 +66,4 @@ - [.getResponseTime()](#getresponsetime)

- `.type(value)` - Sets the header `Content-Type`.
- `.redirect([code,] dest)` - Redirect to the specified URL, the status code is
optional (default to `302`).
- `.redirect(dest, [code,])` - Redirect to the specified URL, the status code is
optional (defaults to `302`).
- `.callNotFound()` - Invokes the custom not found handler.

@@ -304,3 +304,3 @@ - `.serialize(payload)` - Serializes the specified payload using the default

### .redirect([code ,] dest)
### .redirect(dest, [code ,])
<a id="redirect"></a>

@@ -326,3 +326,3 @@

```js
reply.redirect(303, '/home')
reply.redirect('/home', 303)
```

@@ -337,3 +337,3 @@

```js
reply.code(303).redirect(302, '/home')
reply.code(303).redirect('/home', 302)
```

@@ -340,0 +340,0 @@

@@ -27,2 +27,3 @@

- [FSTDEP020](#FSTDEP020)
- [FSTDEP021](#FSTDEP021)

@@ -94,1 +95,2 @@

| <a id="FSTDEP020">FSTDEP020</a> | You are using the deprecated `reply.getReponseTime()` method. | Use the `reply.elapsedTime` property instead. | [#5263](https://github.com/fastify/fastify/pull/5263) |
| <a id="FSTDEP021">FSTDEP021</a> | The `reply.redirect()` method has a new signature: `reply.redirect(url: string, code?: number)`. It will be enforced in `fastify@v5`'. | [#5483](https://github.com/fastify/fastify/pull/5483) |
'use strict'
const VERSION = '4.27.0'
const VERSION = '4.28.0'

@@ -5,0 +5,0 @@ const Avvio = require('avvio')

@@ -5,6 +5,4 @@ // This file is autogenerated by build/build-error-serializer.js, do not edit

'use strict'
const { dependencies } = require('fast-json-stringify/lib/standalone')
const { Serializer, Validator } = dependencies
const Serializer = require('fast-json-stringify/lib/serializer')
const serializerState = {"mode":"standalone"}

@@ -19,2 +17,14 @@ const serializer = Serializer.restoreFromState(serializerState)

const JSON_STR_BEGIN_OBJECT = '{'
const JSON_STR_END_OBJECT = '}'
const JSON_STR_BEGIN_ARRAY = '['
const JSON_STR_END_ARRAY = ']'
const JSON_STR_COMMA = ','
const JSON_STR_COLONS = ':'
const JSON_STR_QUOTE = '"'
const JSON_STR_EMPTY_OBJECT = JSON_STR_BEGIN_OBJECT + JSON_STR_END_OBJECT
const JSON_STR_EMPTY_ARRAY = JSON_STR_BEGIN_ARRAY + JSON_STR_END_ARRAY
const JSON_STR_EMPTY_STRING = JSON_STR_QUOTE + JSON_STR_QUOTE
const JSON_STR_NULL = 'null'

@@ -28,32 +38,79 @@

if (obj === null) return '{}'
if (obj === null) return JSON_STR_EMPTY_OBJECT
let json = '{'
let value
let json = JSON_STR_BEGIN_OBJECT
let addComma = false
if (obj["statusCode"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
value = obj["statusCode"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"statusCode\":"
json += serializer.asNumber(obj["statusCode"])
json += serializer.asNumber(value)
}
if (obj["code"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
value = obj["code"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"code\":"
json += serializer.asString(obj["code"])
if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value.toString())
}
} else {
json += serializer.asString(value)
}
}
if (obj["error"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
value = obj["error"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"error\":"
json += serializer.asString(obj["error"])
if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value.toString())
}
} else {
json += serializer.asString(value)
}
}
if (obj["message"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
value = obj["message"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"message\":"
json += serializer.asString(obj["message"])
if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value.toString())
}
} else {
json += serializer.asString(value)
}
}
return json + '}'
return json + JSON_STR_END_OBJECT

@@ -60,0 +117,0 @@ }

@@ -58,3 +58,3 @@ 'use strict'

} = require('./errors')
const { FSTDEP010, FSTDEP013, FSTDEP019, FSTDEP020 } = require('./warnings')
const { FSTDEP010, FSTDEP013, FSTDEP019, FSTDEP020, FSTDEP021 } = require('./warnings')

@@ -461,5 +461,11 @@ const toString = Object.prototype.toString

Reply.prototype.redirect = function (code, url) {
if (typeof code === 'string') {
url = code
Reply.prototype.redirect = function (url, code) {
if (typeof url === 'number') {
FSTDEP021()
const temp = code
code = url
url = temp
}
if (!code) {
code = this[kReplyHasStatusCode] ? this.raw.statusCode : 302

@@ -466,0 +472,0 @@ }

@@ -171,3 +171,7 @@ 'use strict'

function hasRoute ({ options }) {
return findRoute(options) !== null
const normalizedMethod = options.method?.toUpperCase() ?? ''
return findRoute({
...options,
method: normalizedMethod
}) !== null
}

@@ -174,0 +178,0 @@

@@ -85,2 +85,7 @@ 'use strict'

const FSTDEP021 = createDeprecation({
code: 'FSTDEP021',
message: 'The `reply.redirect()` method has a new signature: `reply.redirect(url: string, code?: number)`. It will be enforced in `fastify@v5`'
})
const FSTWRN001 = createWarning({

@@ -117,4 +122,5 @@ name: 'FastifyWarning',

FSTDEP020,
FSTDEP021,
FSTWRN001,
FSTWRN002
}
{
"name": "fastify",
"version": "4.27.0",
"version": "4.28.0",
"description": "Fast and low overhead web framework, for Node.js",

@@ -5,0 +5,0 @@ "main": "fastify.js",

@@ -39,4 +39,11 @@ 'use strict'

const isNodeVersionGte1819 = semver.gte(process.version, '18.19.0')
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip Node >= v18.19.x', { skip: isNodeVersionGte1819 }, async t => {
// default enable of idle closing idle connection is accidentally backported to 18.19.0 and fixed in 18.20.3
// Refs: https://github.com/nodejs/node/releases/tag/v18.20.3
const isNodeDefaultClosingIdleConnection =
(
semver.gte(process.version, '18.19.0') &&
semver.lt(process.version, '18.20.3')
) ||
semver.gte(process.version, '19.0.0')
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip when Node default closing idle connection', { skip: isNodeDefaultClosingIdleConnection }, async t => {
const fastify = Fastify({

@@ -71,4 +78,4 @@ return503OnClosing: false,

test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip Node < v18.19.x', { skip: !isNodeVersionGte1819 }, async t => {
// Since Node v18, we will always invoke server.closeIdleConnections()
test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip when Node not default closing idle connection', { skip: !isNodeDefaultClosingIdleConnection }, async t => {
// Since Node v19, we will always invoke server.closeIdleConnections()
// therefore our socket will be closed

@@ -75,0 +82,0 @@ const fastify = Fastify({

@@ -8,3 +8,3 @@ 'use strict'

test('hasRoute', t => {
t.plan(4)
t.plan(5)
const test = t.test

@@ -78,2 +78,18 @@ const fastify = Fastify()

})
test('hasRoute - finds a route even if method is not uppercased', t => {
t.plan(1)
fastify.route({
method: 'GET',
url: '/equal',
handler: function (req, reply) {
reply.send({ hello: 'world' })
}
})
t.equal(fastify.hasRoute({
method: 'get',
url: '/equal'
}), true)
})
})

@@ -22,3 +22,3 @@ 'use strict'

const path = require('node:path')
const { FSTDEP010, FSTDEP019, FSTDEP020 } = require('../../lib/warnings')
const { FSTDEP010, FSTDEP019, FSTDEP020, FSTDEP021 } = require('../../lib/warnings')

@@ -254,3 +254,3 @@ const agent = new http.Agent({ keepAlive: false })

fastify.get('/redirect-code', function (req, reply) {
reply.redirect(301, '/')
reply.redirect('/', 301)
})

@@ -263,3 +263,3 @@

fastify.get('/redirect-code-before-call-overwrite', function (req, reply) {
reply.code(307).redirect(302, '/')
reply.code(307).redirect('/', 302)
})

@@ -2100,2 +2100,32 @@

test('redirect with deprecated signature should warn', t => {
t.plan(4)
process.removeAllListeners('warning')
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'DeprecationWarning')
t.equal(warning.code, FSTDEP021.code)
}
const fastify = Fastify()
fastify.get('/', (req, reply) => {
reply.redirect(302, '/new')
})
fastify.get('/new', (req, reply) => {
reply.send('new')
})
fastify.inject({ method: 'GET', url: '/' }, (err, res) => {
t.error(err)
t.pass()
process.removeListener('warning', onWarning)
})
FSTDEP021.emitted = false
})
test('invalid response headers should not crash the server', async t => {

@@ -2102,0 +2132,0 @@ const fastify = Fastify()

@@ -32,3 +32,3 @@ import { Buffer } from 'buffer'

expectAssignable<(key: string) => boolean>(reply.hasHeader)
expectType<{(statusCode: number, url: string): FastifyReply; (url: string): FastifyReply }>(reply.redirect)
expectType<{(statusCode: number, url: string): FastifyReply;(url: string, statusCode?: number): FastifyReply;}>(reply.redirect)
expectType<() => FastifyReply>(reply.hijack)

@@ -35,0 +35,0 @@ expectType<() => void>(reply.callNotFound)

@@ -1055,3 +1055,3 @@ import fastify, {

interface AuxiliaryHandlerProvider extends FastifyTypeProvider { output: 'handler-auxiliary' }
interface AuxiliaryHandlerProvider extends FastifyTypeProvider { output: this['input'] }

@@ -1067,3 +1067,3 @@ // Auxiliary handlers are likely shared for multiple routes and thus should infer as unknown due to potential varying parameters

onRequest: auxiliaryHandler,
schema: { body: null }
schema: { body: 'handler-auxiliary' }
},

@@ -1070,0 +1070,0 @@ (req) => {

@@ -60,5 +60,7 @@ import { Buffer } from 'buffer'

hasHeader(key: HttpHeader): boolean;
// Note: should consider refactoring the argument order for redirect. statusCode is optional so it should be after the required url param
/**
* @deprecated The `reply.redirect()` method has a new signature: `reply.reply.redirect(url: string, code?: number)`. It will be enforced in `fastify@v5`'.
*/
redirect(statusCode: number, url: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
redirect(url: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
redirect(url: string, statusCode?: number): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
hijack(): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;

@@ -65,0 +67,0 @@ callNotFound(): void;

@@ -15,3 +15,3 @@ import { FastifyError } from '@fastify/error'

} from './type-provider'
import { ContextConfigDefault, HTTPMethods, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
import { ContextConfigDefault, HTTPMethods, NoInferCompat, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'

@@ -52,4 +52,4 @@ export interface FastifyRouteConfig {

validatorCompiler?: FastifySchemaCompiler<SchemaCompiler>;
serializerCompiler?: FastifySerializerCompiler<SchemaCompiler>;
validatorCompiler?: FastifySchemaCompiler<NoInferCompat<SchemaCompiler>>;
serializerCompiler?: FastifySerializerCompiler<NoInferCompat<SchemaCompiler>>;
bodyLimit?: number;

@@ -64,4 +64,4 @@ logLevel?: LogLevel;

error: FastifyError,
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, NoInferCompat<SchemaCompiler>, TypeProvider, ContextConfig, Logger>,
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider>
) => void;

@@ -72,22 +72,22 @@ childLoggerFactory?: FastifyChildLoggerFactory<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

// hooks
onRequest?: onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
preParsing?: preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
preValidation?: preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
preHandler?: preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
preSerialization?: preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
onSend?: onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
onResponse?: onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
onTimeout?: onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
onError?: onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
| onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>[];
onRequestAbort?: onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
onRequest?: onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
preParsing?: preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
preValidation?: preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
preHandler?: preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
preSerialization?: preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
onSend?: onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
onResponse?: onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
onTimeout?: onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
onError?: onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
onRequestAbort?: onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>
| onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>[];
}

@@ -169,3 +169,3 @@ /**

url: string;
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInferCompat<SchemaCompiler>, TypeProvider, Logger>;
}

@@ -172,0 +172,0 @@

@@ -91,1 +91,6 @@ import * as http from 'http'

export type HttpHeader = keyof OmitIndexSignature<http.OutgoingHttpHeaders> | (string & Record<never, never>);
// cheat for similar (same?) behavior as NoInfer but for TS <5.4
export type NoInferCompat<SC> = {
[K in keyof SC]: SC[K]
};
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