Search code examples
node.jsproxynode-http-proxy

How to get HTTP METHOD in http-proxy when proxying a session?


I am using Node.js and module http-proxy (link here) to proxy requests in my server.

Detecting DELETE requests

What I want to achieve is performing certain action when an HTTP DELETE request is sent.

Poor doc

How can I do this? Module http-proxy comes with a very poor documentation and objects like res, req and proxyRes are not properly documented. From the doc it is possible to understand that object proxyRes has a property called headers and nothing more.


Solution

  • req.method is the property you want. It will be a string corresponding to the HTTP request method such as 'DELETE', 'GET', 'POST', etc. node-http-proxy does not document this because it is part of the node core http.IncomingMessage standard API (docs linked above).