server.js: always respond with raw content for some user agents
This commit is contained in:
parent
0209375865
commit
38d907e1d7
12
server.js
12
server.js
|
@ -8,6 +8,8 @@ var route = require('connect-route');
|
||||||
var connect_st = require('st');
|
var connect_st = require('st');
|
||||||
var connect_rate_limit = require('connect-ratelimit');
|
var connect_rate_limit = require('connect-ratelimit');
|
||||||
|
|
||||||
|
var RAW_USER_AGENTS = /(curl|wget|httpie|lwp-request)/i;
|
||||||
|
|
||||||
var DocumentHandler = require('./lib/document_handler');
|
var DocumentHandler = require('./lib/document_handler');
|
||||||
|
|
||||||
// Load the configuration and set some defaults
|
// Load the configuration and set some defaults
|
||||||
|
@ -125,11 +127,11 @@ app.use(route(function(router) {
|
||||||
// get documents
|
// get documents
|
||||||
router.get('/documents/:id', function(request, response, next) {
|
router.get('/documents/:id', function(request, response, next) {
|
||||||
var skipExpire = !!config.documents[request.params.id];
|
var skipExpire = !!config.documents[request.params.id];
|
||||||
return documentHandler.handleGet(
|
var args = [request.params.id, response, skipExpire];
|
||||||
request.params.id,
|
var fn = RAW_USER_AGENTS.test(request.headers['user-agent'] || '')
|
||||||
response,
|
? documentHandler.handleRawGet
|
||||||
skipExpire
|
: documentHandler.handleGet;
|
||||||
);
|
return fn.apply(documentHandler, args);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue