From d2d77047b38f4432977e4a0c92576b5ee25793a0 Mon Sep 17 00:00:00 2001 From: Nathaniel Warner Date: Fri, 4 Oct 2019 11:46:44 -0500 Subject: [PATCH] Initial implementation of serving webp images when possible, based on inspection of request headers. --- server.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index f4fc749..a4a0a19 100644 --- a/server.js +++ b/server.js @@ -32,7 +32,14 @@ http.createServer( function( request, response ) { return response.end() } - return tachyon.s3( config, decodeURI( params.pathname.substr(1) ), params.query, function( err, data, info ) { + let args = params.query; + + let accept = request.headers['accept'] ? request.headers['accept'] : ""; + if (accept.includes('webp')) { + args.webp = true + } + + return tachyon.s3( config, decodeURI( params.pathname.substr(1) ), args, function( err, data, info ) { if ( err ) { if ( debug ) { console.error( Date(), err )