Skip to content

Allow overriding or modifying the queryString when proxying websockets #348

@ttshivers

Description

@ttshivers

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

It would be great to have the ability to overwrite or modify the queryString when proxying websockets. Possibly adding a queryString property to the wsClientOptions, in the same way that there is already a rewriteRequestHeaders in the wsClientOptions

Motivation

When proxying regular http connections, the queryString in replyOptions can be used to rewrite or modify the query string. https://github.com/fastify/fastify-reply-from?tab=readme-ov-file#querystring-or-querystringsearch-requrl

A websocket API I want to proxy requires passing an auth token as query parameter and I want to make a proxy with this library to inject it.

Example

fastify.register(require('@fastify/http-proxy'), {
   websocket: true,
   wsUpstream: 'wss://some-domain.com',
   wsClientOptions: {
      queryString(search, reqUrl, req) {
          return {
            authToken: req.authToken
          };
      }
   }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions