BVB Source Codes

prerender Show httpHeaders.js Source code

Return Download prerender: download httpHeaders.js Source code - Download prerender Source code - Type:.js
  1. var he = require('he');
  2.  
  3. module.exports = {
  4.     afterPhantomRequest: function(req, res, next) {
  5.         if(req.prerender.documentHTML) {
  6.             var statusMatch = /<meta[^<>]*(?:name=['"]prerender-status-code['"][^<>]*content=['"]([0-9]{3})['"]|content=['"]([0-9]{3})['"][^<>]*name=['"]prerender-status-code['"])[^<>]*>/i,
  7.                 headerMatch = /<meta[^<>]*(?:name=['"]prerender-header['"][^<>]*content=['"]([^'"]*?): ?([^'"]*?)['"]|content=['"]([^'"]*?): ?([^'"]*?)['"][^<>]*name=['"]prerender-header['"])[^<>]*>/gi,
  8.                 head = req.prerender.documentHTML.toString().split('</head>', 1).pop(),
  9.                 statusCode = 200,
  10.                 match;
  11.  
  12.             if (match = statusMatch.exec(head)) {
  13.                 statusCode = match[1] || match[2];
  14.                 req.prerender.documentHTML = req.prerender.documentHTML.toString().replace(match[0], '');
  15.             }
  16.  
  17.             while (match = headerMatch.exec(head)) {
  18.                 res.setHeader(match[1] || match[3], he.decode(match[2] || match[4]));
  19.                 req.prerender.documentHTML = req.prerender.documentHTML.toString().replace(match[0], '');
  20.             }
  21.  
  22.             if (statusCode != 200) {
  23.                 return res.send(statusCode, req.prerender.documentHTML);
  24.             }
  25.         }
  26.  
  27.         next();
  28.     }
  29. };
  30.  
downloadhttpHeaders.js Source code - Download prerender Source code
Related Source Codes/Software:
libsodium - A modern and easy-to-use crypto library. 2017-01-09
Side-Menu.Android - Side menu with some categories to choose. ... 2017-01-09
docker-gitlab - Dockerized GitLab http://www.da... 2017-01-09
sinon - Test spies, stubs and mocks for JavaScript. ... 2017-01-09
in-view - Get notified when a DOM element enters or exits th... 2017-01-09
falcon - Falcon is a low-level, high-performance Python fra... 2017-01-09
ImageOptim - GUI image optimizer for Mac htt... 2017-01-09
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
Gource - oftware version control visualization ... 2017-01-10
mongo-express - Web-based MongoDB admin interface, written with No... 2017-05-17
XCL-Charts - Android charting libraries (XCL-Charts is a free c... 2017-05-17
scrollMonitor - A simple and fast API to monitor elements as you s... 2017-05-16
XCDYouTubeKit - YouTube video player for iOS, tvOS and macOS 2017-05-16
rails-erd - Generate Entity-Relationship Diagrams for Rails ap... 2017-05-16
np - A better `npm publish` 2017-05-16
android - Smartisan open source code for full build.(repo ma... 2017-05-16
word_cloud - A little word cloud generator in Pytho 2017-05-16
mobileplayer-ios - 2017-05-16
Destroy-Windows-10-Spying - Destroy Windows Spying tool ... 2017-05-15

 Back to top