<commit_before>const { resolve } = require('path')
const webpack = require('webpack')
const middleware = require('webpack-dev-middleware')
const conf = require('./webpack.server.js')
const compiler = webpack(conf)
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const url = require('url')
app.use(bodyParser.json({ type: 'application/json' }))

const { exec } = require('child_process')

/**
 * Constants.
 */
var SERVER_SOFTWARE = 'Node/' + process.version
var SERVER_PROTOCOL = 'HTTP/1.1'
var GATEWAY_INTERFACE = 'CGI/1.1'

const perl = (req, res) => {
  const file = resolve.apply(null, [__dirname].concat(req.url.split('/')))

  if (!req.hasOwnProperty('uri')) {
    req.uri = url.parse(req.url)
  }

  var host = (req.headers.host || '').split(':')
  var address = host[0]
  var port = host[1]

  var env = {}

  // These meta-variables below can be overwritten by a
  // user's 'env' object in options
  Object.assign(env, {
    GATEWAY_INTERFACE: GATEWAY_INTERFACE,
    SCRIPT_NAME: file,
    SERVER_NAME: address || 'unknown',
    SERVER_PORT: port || 80,
    SERVER_PROTOCOL: SERVER_PROTOCOL,
    SERVER_SOFTWARE: SERVER_SOFTWARE,
  })

  // The client HTTP request headers are attached to the env as well,
  // in the format: "User-Agent" -> "HTTP_USER_AGENT"
  for (var header in req.headers) {
    var name = 'HTTP_' + header.toUpperCase().replace(/-/g, '_')
    env[name] = req.headers[header]
  }

  // These final environment variables take precedence over user-specified ones.
  env.REQUEST_METHOD = req.method.toUpperCase()
  env.QUERY_STRING = req.uri.query || ''
  env.REMOTE_ADDR = req.connection.remoteAddress
  env.REMOTE_PORT = req.connection.remotePort
  if ('content-length' in req.headers) {
    env.CONTENT_LENGTH = req.headers['content-length']
  }
  if ('content-type' in req.headers) {
    env.CONTENT_TYPE = req.headers['content-type']
  }
  if ('authorization' in req.headers) {
    var auth = req.headers.authorization.split(' ')
    env.AUTH_TYPE = auth[0]
  }

  var stringifiedEnv = []
  for (var k in env) {
    stringifiedEnv.push(`export ${k}="${('' + env[k]).replace(';', ';')}"`)
  }

  const sendErr = msg => res.status(500).send(msg || 'Request Failed')
  exec(
    `${stringifiedEnv.join(' && ')} && carton exec ${file} 'POSTDATA=${JSON.stringify(req.body)}'`,<commit_msg>remove POSTDATA and send raw string<commit_after>const { resolve } = require('path')
const webpack = require('webpack')
const middleware = require('webpack-dev-middleware')
const conf = require('./webpack.server.js')
const compiler = webpack(conf)
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const url = require('url')
app.use(bodyParser.json({ type: 'application/json' }))

const { exec } = require('child_process')

/**
 * Constants.
 */
var SERVER_SOFTWARE = 'Node/' + process.version
var SERVER_PROTOCOL = 'HTTP/1.1'
var GATEWAY_INTERFACE = 'CGI/1.1'

const perl = (req, res) => {
  const file = resolve.apply(null, [__dirname].concat(req.url.split('/')))

  if (!req.hasOwnProperty('uri')) {
    req.uri = url.parse(req.url)
  }

  var host = (req.headers.host || '').split(':')
  var address = host[0]
  var port = host[1]

  var env = {}

  // These meta-variables below can be overwritten by a
  // user's 'env' object in options
  Object.assign(env, {
    GATEWAY_INTERFACE: GATEWAY_INTERFACE,
    SCRIPT_NAME: file,
    SERVER_NAME: address || 'unknown',
    SERVER_PORT: port || 80,
    SERVER_PROTOCOL: SERVER_PROTOCOL,
    SERVER_SOFTWARE: SERVER_SOFTWARE,
  })

  // The client HTTP request headers are attached to the env as well,
  // in the format: "User-Agent" -> "HTTP_USER_AGENT"
  for (var header in req.headers) {
    var name = 'HTTP_' + header.toUpperCase().replace(/-/g, '_')
    env[name] = req.headers[header]
  }

  // These final environment variables take precedence over user-specified ones.
  env.REQUEST_METHOD = req.method.toUpperCase()
  env.QUERY_STRING = req.uri.query || ''
  env.REMOTE_ADDR = req.connection.remoteAddress
  env.REMOTE_PORT = req.connection.remotePort
  if ('content-length' in req.headers) {
    env.CONTENT_LENGTH = req.headers['content-length']
  }
  if ('content-type' in req.headers) {
    env.CONTENT_TYPE = req.headers['content-type']
  }
  if ('authorization' in req.headers) {
    var auth = req.headers.authorization.split(' ')
    env.AUTH_TYPE = auth[0]
  }

  var stringifiedEnv = []
  for (var k in env) {
    stringifiedEnv.push(`export ${k}="${('' + env[k]).replace(';', ';')}"`)
  }

  const sendErr = msg => res.status(500).send(msg || 'Request Failed')
  exec(
    `${stringifiedEnv.join(' && ')} && carton exec ${file} '${JSON.stringify(req.body)}'`,
{'fraction_non_alphanumeric': 0.16326100695175902, 'fraction_numerical': 0.005055824731409311, 'mean_word_length': 3.85480572597137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1720392', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1594, 'n_words': 372}