<commit_before>var http = require('http')
  , https = require('https');

  //////////////////////
 // gdata CORS proxy //
//////////////////////

http.createServer(function (req, res) {
  var dataStr = '';
  req.on('data', function(chunk) {
    dataStr += chunk;
  });
  req.on('end', function() {
    console.log('\nA.URL:'+req.url);
    console.log('\nA.METHOD:'+req.method);
    console.log('\nA.HEADERS:'+JSON.stringify(req.headers));
    console.log('\nA.DATA:'+dataStr);
    var options =
      { 'host': 'docs.google.com'
      , 'port': 443
      , 'method': req.method
      , 'path': req.url
      , 'headers': req.headers
      };
    var requestedOrigin = options.headers.origin;
    var requestedMethod = options.headers['access-control-request-method'];
    var requestedHeaders = options.headers['access-control-request-headers'];
    options.headers.origin = 'http://myfavouritesandwich.org';
    options.headers['access-control-request-method'] = undefined;
    options.headers['access-control-request-headers'] = undefined;

    console.log('\nB:'+JSON.stringify(options));
    var req2 = https.request(options, function(res2) {
      var responseHeaders = res2.headers;
      console.log('\nC.HEADERS:'+JSON.stringify(responseHeaders));
      //add CORS to response:
      responseHeaders['Access-Control-Allow-Origin'] = requestedOrigin;
      responseHeaders['Access-Control-Allow-Method'] = requestedMethod;
      responseHeaders['Access-Control-Allow-Headers'] = requestedHeaders;
      responseHeaders['Access-Control-Allow-Credentials'] = 'true';
      //replace status with 200:
      responseHeaders['X-Status'] = res2.statusCode;
      res.writeHead(200, responseHeaders);
      res2.setEncoding('utf8');
      var res2Data = '';
      res.write('START!');
      res2.on('data', function (chunk) {
        res2Data += chunk;
        res.write(chunk);
        res.write('DATA!');
      });
      res2.on('end', function() {
        console.log('\nC.DATA:'+res2Data);
        res.write('END!');
        res.end();
      });
    });
    req2.write(dataStr);
    req2.end();
  });
}).listen(9002);
<commit_msg>force end on first chunk, unset 'host' header<commit_after>var http = require('http')
  , https = require('https');

  //////////////////////
 // gdata CORS proxy //
//////////////////////

http.createServer(function (req, res) {
  var dataStr = '';
  req.on('data', function(chunk) {
    dataStr += chunk;
  });
  req.on('end', function() {
    console.log('\nA.URL:'+req.url);
    console.log('\nA.METHOD:'+req.method);
    console.log('\nA.HEADERS:'+JSON.stringify(req.headers));
    console.log('\nA.DATA:'+dataStr);
    var options =
      { 'host': 'docs.google.com'
      , 'port': 443
      , 'method': req.method
      , 'path': req.url
      , 'headers': req.headers
      };
    var requestedOrigin = options.headers.origin;
    var requestedMethod = options.headers['access-control-request-method'];
    var requestedHeaders = options.headers['access-control-request-headers'];
    options.headers.origin = 'http://myfavouritesandwich.org';
    options.headers['access-control-request-method'] = undefined;
    options.headers['access-control-request-headers'] = undefined;
    options.headers.host = undefined;

    console.log('\nB:'+JSON.stringify(options));
    var req2 = https.request(options, function(res2) {
      var responseHeaders = res2.headers;
      console.log('\nC.HEADERS:'+JSON.stringify(responseHeaders));
      //add CORS to response:
      responseHeaders['Access-Control-Allow-Origin'] = requestedOrigin;
      responseHeaders['Access-Control-Allow-Method'] = requestedMethod;
      responseHeaders['Access-Control-Allow-Headers'] = requestedHeaders;
      responseHeaders['Access-Control-Allow-Credentials'] = 'true';
      //replace status with 200:
      responseHeaders['X-Status'] = res2.statusCode;
      res.writeHead(200, responseHeaders);
      res2.setEncoding('utf8');
      var res2Data = '';
      res.write('START!');
      res2.on('data', function (chunk) {
        res2Data += chunk;
        res.write(chunk);
        res.write('DATA!');
        res.end();
      });
      res2.on('end', function() {
        console.log('\nC.DATA:'+res2Data);
        res.write('END!');
        res.end();
      });
    });
    req2.write(dataStr);
    req2.end();
  });
}).listen(9002);

{'fraction_non_alphanumeric': 0.1911865962818453, 'fraction_numerical': 0.011934817535001148, 'mean_word_length': 2.8600531443755535, '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': '5663732', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1327, 'n_words': 206}