dvonlehman / express-request-proxy

Advanced streaming http request proxy middleware for Express with support for custom routes, caching, and response transforms.
95 stars 38 forks source link

Cache does not work with images #16

Open JMLX42 opened 8 years ago

JMLX42 commented 8 years ago

Hello,

I'm trying to use this module to proxy and cache some images coming from external services. It works when I don't set the cache option.

exports.proxy = function(req, res, next)
{
    if (!req.headers['referer'])
        return res.status(400).send();

    var ref_parts = url.parse(req.headers['referer'], true);
    if (ref_parts.host != config.hostname)
        return res.status(400).send();

    return requestProxy({
        cache: redis.createClient(),
        cacheMaxAge: 3600,
        url: req.query.url
    })(req, res, next);
}

The very same code works for other requests/mime-types such as plain HTML or text.

How can we solve this?

j commented 6 years ago

@promethe42 try: const redisClient = redis.createClient({ return_buffers: true });