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

@fastify/reply-from

Package Overview
Dependencies
Maintainers
19
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/reply-from - npm Package Compare versions

Comparing version 9.0.1 to 9.0.2

test/undici-connect-timeout.test.js

3

index.js

@@ -20,2 +20,3 @@ 'use strict'

ConnectionResetError,
ConnectTimeoutError,
UndiciSocketError,

@@ -161,2 +162,4 @@ InternalServerError

onError(this, { error: new UndiciSocketError() })
} else if (err.code === 'UND_ERR_CONNECT_TIMEOUT') {
onError(this, { error: new ConnectTimeoutError() })
} else {

@@ -163,0 +166,0 @@ onError(this, { error: new InternalServerError(err.message) })

@@ -12,3 +12,4 @@ 'use strict'

module.exports.ConnectionResetError = createError('ECONNRESET', 'Connection Reset', 500)
module.exports.ConnectTimeoutError = createError('UND_ERR_CONNECT_TIMEOUT', 'Connect Timeout Error', 500)
module.exports.UndiciSocketError = createError('UND_ERR_SOCKET', 'Undici Socket Error', 500)
module.exports.InternalServerError = createError('FST_REPLY_FROM_INTERNAL_SERVER_ERROR', '%s', 500)

8

package.json
{
"name": "@fastify/reply-from",
"version": "9.0.1",
"version": "9.0.2",
"description": "forward your HTTP request to another server, for fastify",

@@ -35,3 +35,3 @@ "main": "index.js",

"@sinonjs/fake-timers": "^10.0.0",
"@types/node": "^18.0.0",
"@types/node": "^20.1.4",
"@types/tap": "^15.0.7",

@@ -50,3 +50,3 @@ "fastify": "^4.0.2",

"tap": "^16.2.0",
"tsd": "^0.26.0"
"tsd": "^0.28.0"
},

@@ -59,3 +59,3 @@ "dependencies": {

"pump": "^3.0.0",
"tiny-lru": "^10.0.0",
"tiny-lru": "^11.0.0",
"undici": "^5.19.1"

@@ -62,0 +62,0 @@ },

@@ -315,2 +315,52 @@ # @fastify/reply-from

Only http1! As http2 uses one connection for the whole session only the base upstream is used. If you want to
have different upstreams based on the request you can add multiple Fastify.register's with different
ContraintStrategies.
e.g.:
Route grpc-web/http1 and grpc/http2 to different routes with a ContentType-ConstraintStrategy:
```
const contentTypeMatchContraintStrategy = {
// strategy name for referencing in the route handler `constraints` options
name: 'contentType',
// storage factory for storing routes in the find-my-way route tree
storage: function () {
let handlers = {}
return {
get: (type: any) => { return handlers[type] || null },
set: (type: any, store: any) => { handlers[type] = store }
}
},
// function to get the value of the constraint from each incoming request
deriveConstraint: (req: any, ctx: any) => {
return req.headers['content-type']
},
// optional flag marking if handlers without constraints can match requests that have a value for this constraint
mustMatchWhenDerived: true
}
server.addConstraintStrategy(contentTypeMatchContraintStrategy);
```
and then 2 different upstreams with different register's:
```
// grpc-web / http1
server.register(fastifyHttpProxy, {
// Although most browsers send with http2, nodejs cannot handle this http2 request
// therefore we have to transport to the grpc-web-proxy via http1
http2: false,
upstream: 'http://grpc-web-proxy',
constraints: { "contentType": "application/grpc-web+proto" }
});
// grpc / http2
server.register(fastifyHttpProxy, {
http2: true,
upstream: 'http://grpc.server',
constraints: { "contentType": "application/grpc+proto" }
});
```
#### `queryString` or `queryString(search, reqUrl)`

@@ -317,0 +367,0 @@

@@ -42,3 +42,6 @@ 'use strict'

get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
get({
url: `http://localhost:${instance.server.address().port}`,
agent: false
}, (err, res, data) => {
t.error(err)

@@ -45,0 +48,0 @@ t.equal(res.headers['content-type'], 'text/plain')

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

t.test('use a custom instance of \'undici\'', async t => {
t.plan(3)
t.teardown(target.close.bind(target))

@@ -28,3 +29,2 @@

t.test('disableRequestLogging is set to true', t => {
t.plan(10)
const logStream = split(JSON.parse)

@@ -74,3 +74,2 @@ const instance = Fastify({

t.test('disableRequestLogging is set to false', t => {
t.plan(8)
const logStream = split(JSON.parse)

@@ -120,3 +119,2 @@ const instance = Fastify({

t.test('disableRequestLogging is not defined', t => {
t.plan(8)
const logStream = split(JSON.parse)

@@ -123,0 +121,0 @@ const instance = Fastify({

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