From 38d907e1d79a792e3babeba0370be5971d7d02a8 Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 1 Apr 2016 13:22:30 +0200 Subject: [PATCH] server.js: always respond with raw content for some user agents --- server.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server.js b/server.js index 2e138f2..123dd86 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,8 @@ var route = require('connect-route'); var connect_st = require('st'); var connect_rate_limit = require('connect-ratelimit'); +var RAW_USER_AGENTS = /(curl|wget|httpie|lwp-request)/i; + var DocumentHandler = require('./lib/document_handler'); // Load the configuration and set some defaults @@ -125,11 +127,11 @@ app.use(route(function(router) { // get documents router.get('/documents/:id', function(request, response, next) { var skipExpire = !!config.documents[request.params.id]; - return documentHandler.handleGet( - request.params.id, - response, - skipExpire - ); + var args = [request.params.id, response, skipExpire]; + var fn = RAW_USER_AGENTS.test(request.headers['user-agent'] || '') + ? documentHandler.handleRawGet + : documentHandler.handleGet; + return fn.apply(documentHandler, args); }); }));