Skip to content

Provide a possibility to validate request payload before proxying the request #311

@kovalenp

Description

@kovalenp

Prerequisites

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

🚀 Feature Proposal

I would like to have the possibility to validate the request payload before proxying it further.

E.g.

Currently, request.body in preHandler is a stream

.register(require('@fastify/http-proxy'), {
      upstream: process.env.API,
      prefix: '/v1/:domain/:apiKey',
      rewritePrefix: '/full/:domain',
    })

so I can't have something like this:

.register(require('@fastify/http-proxy'), {
      upstream: process.env.API,
      prefix: '/v1/:domain/:apiKey',
      rewritePrefix: '/full/:domain',
      preHandelr: (req) => { validate(req.body)}
    })

Motivation

I have and rpc api which I'm proxying via http-proxy. I would like to check request json payload and restrict certain methods (not to proxy it further and reply with error)

I have no possibility to do so, since request.body is not parsed in preHander.

Example

No response

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