Node-http-proxy: http-proxy does not support the Expected header: 100-continue

Created on 27 Nov 2017  路  5Comments  路  Source: http-party/node-http-proxy

If I use http-proxy only as requester, there is a problem with 100-continue.
When we have a response from server with status 100 the requester in http-proxy (proxyReq in web-incoming) do not handle event "continue" and "socket hang up"

Most helpful comment

This is my workaround, maybe it helps someone:

const proxy = httpProxy.createProxyServer({
    // ...
});

proxy.before('web', 'stream', (req, res, options) => {
    if (req.headers.expect) {
        req.__expectHeader = req.headers.expect;
        delete req.headers.expect;
    }
});

proxy.on('proxyReq', (proxyReq, req, res, options) => {
    // edit proxy request headers with proxyReq.setHeader(...) and proxyReq.removeHeader(...)

    if (req.__expectHeader) {
        proxyReq.setHeader('Expect', req.__expectHeader);
    }
});

proxy.listen(3000);

All 5 comments

The "proxyReq" callback is invoked too late to apply additional headers.

Would it be possible to set request headers after the proxyReq event callback? Or perhaps detect whether Expect: 100-continue is included in the request headers and delay forwarding that header until after the proxyReq event callback has been processed?

As a workaround, I currently set all my headers on the incoming request object inside the HTTP server's "request" event callback. That way they get copied onto the outgoing proxied request before the Expect: 100-continue header is processed for the outgoing request.

This is my workaround, maybe it helps someone:

const proxy = httpProxy.createProxyServer({
    // ...
});

proxy.before('web', 'stream', (req, res, options) => {
    if (req.headers.expect) {
        req.__expectHeader = req.headers.expect;
        delete req.headers.expect;
    }
});

proxy.on('proxyReq', (proxyReq, req, res, options) => {
    // edit proxy request headers with proxyReq.setHeader(...) and proxyReq.removeHeader(...)

    if (req.__expectHeader) {
        proxyReq.setHeader('Expect', req.__expectHeader);
    }
});

proxy.listen(3000);

Anything new on this ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

catamphetamine picture catamphetamine  路  6Comments

mohammad-goldast picture mohammad-goldast  路  3Comments

SET001 picture SET001  路  5Comments

DominicTobias picture DominicTobias  路  3Comments

miton18 picture miton18  路  5Comments