Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

responseInterceptor uses more constrained types than onProxyRes provides #708

Closed
2 tasks done
marchuffnagle opened this issue Feb 11, 2022 · 2 comments · Fixed by #882
Closed
2 tasks done

responseInterceptor uses more constrained types than onProxyRes provides #708

marchuffnagle opened this issue Feb 11, 2022 · 2 comments · Fixed by #882

Comments

@marchuffnagle
Copy link

Checks

Describe the bug (be clear and concise)

The onProxyRes option expects an OnProxyResCallback, which is defined as

export type OnProxyResCallback = (
  proxyRes: http.IncomingMessage,
  req: Request,
  res: Response
) => void;

The req and res parameters extend express's Request and Response.

The documentation demonstrates using responseInterceptor to build that callback. Although the onProxyRes is going to receive a Request instance, responseInterceptor only allows you to expect an http.IncomingMessage. It seems like you should be able to expect a Request for the req argument.

export function responseInterceptor(interceptor: Interceptor) {

where Interceptor is

type Interceptor = (
  buffer: Buffer,
  proxyRes: http.IncomingMessage,
  req: http.IncomingMessage,
  res: http.ServerResponse
) => Promise<Buffer | string>;

This came up as an issue for me because there is information in the express Request that I need to access in my onProxyRes callback, but can't in a type-safe manner.

Step-by-step reproduction instructions

n/a

Expected behavior (be clear and concise)

responseInterceptor should type req as Request and res as Response.

How is http-proxy-middleware used in your project?

n/a

What http-proxy-middleware configuration are you using?

n/a

What OS/version and node/version are you seeing the problem?

n/a

Additional context (optional)

No response

@cdaringe
Copy link

#721 converts:

  proxyRes: http.IncomingMessage,
  req: express.Request,

to

  proxyRes: http.IncomingMessage,
  req: http.IncomingMessage,

which I think satisfies your use case?

@marchuffnagle
Copy link
Author

Closed by #721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants