<commit_before>var http = require('http');
var fs = require('fs');
var path = require('path');
var instructions = path.join(__dirname, './info.html');

var info = function (request, response) {
  //check if request is http or https
  //note: does not work in Heroku becouse of inside
  var baseUrl = (request.connection.encrypted ? "https" : "http") +
     '://' + request.headers.host;

     console.log(request.headers['x-forwarded-proto']);

  fs.readFile(instructions, 'utf8', function(error, content) {
    if (error) {
      if(error.code == 'ENOENT'){
        response.writeHead(404);
        response.end('404 - Where is my file?\n');
      } else {
          response.writeHead(500);
          response.end('500 - Something strange just happened :(\n');
        }
    } else {
        response.writeHead(200, { 'Content-Type': 'text/html' });
        response.end(
          content.replace(new RegExp("_HOSTNAME_", 'g'),baseUrl),
          'utf-8');
    }
  });
};

module.exports = info;
<commit_msg>add req.headers['x-forwarded-proto'] check<commit_after>var http = require('http');
var fs = require('fs');
var path = require('path');
var instructions = path.join(__dirname, './info.html');

var info = function (request, response) {
  //check if request is http or https
  //needs double check due to forwarding possible use
  var baseUrl = (
    (request.connection.encrypted ||
      request.headers['x-forwarded-proto'] === 'https') ? "https" : "http") +
     '://' + request.headers.host;

     //console.log(request.headers['x-forwarded-proto']);

  fs.readFile(instructions, 'utf8', function(error, content) {
    if (error) {
      if(error.code == 'ENOENT'){
        response.writeHead(404);
        response.end('404 - Where is my file?\n');
      } else {
          response.writeHead(500);
          response.end('500 - Something strange just happened :(\n');
        }
    } else {
        response.writeHead(200, { 'Content-Type': 'text/html' });
        response.end(
          content.replace(new RegExp("_HOSTNAME_", 'g'),baseUrl),
          'utf-8');
    }
  });
};

module.exports = info;

{'fraction_non_alphanumeric': 0.17075471698113207, 'fraction_numerical': 0.016037735849056604, 'mean_word_length': 2.8216216216216217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3693042', 'n_tokens_mistral': 677, 'n_tokens_neox': 650, 'n_words': 151}