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

fastify-http-proxy

Package Overview
Dependencies
Maintainers
13
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-http-proxy - npm Package Compare versions

Comparing version 4.3.1 to 4.4.0

5

example.js

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

const origin = Fastify()
origin.get('/', async (request, reply) => {

@@ -13,2 +14,6 @@ return 'this is root'

origin.get('/redirect', async (request, reply) => {
return reply.redirect(302, 'https://fastify.io')
})
origin.get('/a', async (request, reply) => {

@@ -15,0 +20,0 @@ return 'this is a'

8

index.js
'use strict'
const From = require('fastify-reply-from')

@@ -7,2 +6,3 @@ const WebSocket = require('ws')

const httpMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS']
const urlPattern = /^https?:\/\//

@@ -35,2 +35,6 @@ function liftErrorCode (code) {

function isExternalUrl (url = '') {
return urlPattern.test(url)
};
function proxyWebSockets (source, target) {

@@ -153,3 +157,3 @@ function close (code, reason) {

const location = headers.location
if (location) {
if (location && !isExternalUrl(location)) {
headers.location = location.replace(rewritePrefix, fastify.prefix)

@@ -156,0 +160,0 @@ }

{
"name": "fastify-http-proxy",
"version": "4.3.1",
"version": "4.4.0",
"description": "proxy http requests, for Fastify",

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

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

origin.get('/redirect', async (request, reply) => {
return reply.redirect(302, 'https://fastify.io')
})
origin.post('/this-has-data', async (request, reply) => {

@@ -62,2 +66,23 @@ if (request.body.hello === 'world') {

test('redirects passthrough', async t => {
const server = Fastify()
server.register(proxy, {
upstream: `http://localhost:${origin.server.address().port}`
})
await server.listen(0)
t.tearDown(server.close.bind(server))
const {
headers: { location },
statusCode
} = await got(
`http://localhost:${server.server.address().port}/redirect`, {
followRedirect: false
}
)
t.equal(location, 'https://fastify.io')
t.equal(statusCode, 302)
})
test('no upstream will throw', async t => {

@@ -64,0 +89,0 @@ const server = Fastify()

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