<commit_before><?php

/**
 * Handle CGI Request
 **/

namespace SimpleHTTPServer\Module;

use SimpleHTTPServer\IModule;
use SimpleHTTPServer\Request;
use SimpleHTTPServer\Module;

class CGI extends Module implements IModule {
	
	public function __construct(Request $request) {
		parent::__construct($request);
		
		$config = new \SimpleHTTPServer\Config;
		$file = $request->getCGIVar('SCRIPT_FILENAME');
		
		if (	is_file($file) == false
			||	preg_match("/\.php$/", $file) == false
			) {
			$this->valid = false;
			return false;
		}
		
		
		$this->status = 200;
		$this->setHeader('Content-Type', 'text/html');
		
		// PHP scripts
		$cmdIO = array(
			  0 => array('pipe', 'r') // stdin
			, 1 => array('pipe', 'w') // stdout
			, 2 => array('file', $config->logPath, 'aw') // stderr
			);
		
		// REDIRECT_STATUS is required by php-cgi
		$request->setCGIVar('REDIRECT_STATUS', 200);
		$request->setCGIVar('GATEWAY_INTERFACE', 'CGI/1.1');
		
		$cmdEnv = $request->getCGIVars();
		
		$cmdHadler = proc_open(
			  $config->phpCGIPath, $cmdIO, $cmdPipes
			, $request->getCGIVar('DOCUMENT_ROOT'), $cmdEnv
			);
			
		if (is_resource($cmdHadler)) {
			
			if ($request->getCGIVar('REQUEST_METHOD') == 'POST') {
				$postMessage = $request->getPostMessage();
				if (strlen($postMessage)) {
					// POST Method, write POST Message to STDIN
					fwrite($cmdPipes[0], $request->getPostMessage()."\n");
				}
			}
			
			fclose($cmdPipes[0]);
			
			$this->content = stream_get_contents($cmdPipes[1]);
			proc_close($cmdHadler);
		}
	}
	
	public function getContent() {
		return 'HTTP/'.$this->httpVersion
		.' '.$this->status
		.' '.$this->getStatusMessage()."\r\n"<commit_msg>fix PHP session path error, add TEMP into CGI variables<commit_after><?php

/**
 * Handle CGI Request
 **/

namespace SimpleHTTPServer\Module;

use SimpleHTTPServer\IModule;
use SimpleHTTPServer\Request;
use SimpleHTTPServer\Module;

class CGI extends Module implements IModule {
	
	public function __construct(Request $request) {
		parent::__construct($request);
		
		$config = new \SimpleHTTPServer\Config;
		$file = $request->getCGIVar('SCRIPT_FILENAME');
		
		if (	is_file($file) == false
			||	preg_match("/\.php$/", $file) == false
			) {
			$this->valid = false;
			return false;
		}
		
		
		$this->status = 200;
		$this->setHeader('Content-Type', 'text/html');
		
		// PHP scripts
		$cmdIO = array(
			  0 => array('pipe', 'r') // stdin
			, 1 => array('pipe', 'w') // stdout
			, 2 => array('file', $config->logPath, 'aw') // stderr
			);
		
		// REDIRECT_STATUS is required by php-cgi
		$request->setCGIVar('REDIRECT_STATUS', 200);
		$request->setCGIVar('GATEWAY_INTERFACE', 'CGI/1.1');
		$request->setCGIVar('TEMP', $_SERVER['TEMP']);
		
		$cmdEnv = $request->getCGIVars();
		
		$cmdHadler = proc_open(
			  $config->phpCGIPath, $cmdIO, $cmdPipes
			, $request->getCGIVar('DOCUMENT_ROOT'), $cmdEnv
			);
			
		if (is_resource($cmdHadler)) {
			
			if ($request->getCGIVar('REQUEST_METHOD') == 'POST') {
				$postMessage = $request->getPostMessage();
				if (strlen($postMessage)) {
					// POST Method, write POST Message to STDIN
					fwrite($cmdPipes[0], $request->getPostMessage()."\n");
				}
			}
			
			fclose($cmdPipes[0]);
			
			$this->content = stream_get_contents($cmdPipes[1]);
			proc_close($cmdHadler);
		}
	}
	
	public function getContent() {
		return 'HTTP/'.$this->httpVersion
		.' '.$this->status
		.' '.$this->getStatusMessage()."\r\n"
{'fraction_non_alphanumeric': 0.18057574876417562, 'fraction_numerical': 0.008141901715615005, 'mean_word_length': 3.5203679369250986, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '5729494', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1209, 'n_words': 222}