<commit_before><?PHP

namespace Firelit;

class ServerRequest {
	
	// All properties accessible via magic getter method
	private $ip, $proxies, $host, $path, $method, $secure, $referer, $cli, $headers;
	private $post, $get, $cookie;
	
	public static $loadBalanced = false;

	// $filter should be a filtering function, if supplied, which filters a string value by reference
	public function __construct($filter = false, $bodyFormat = 'querystring') { 
		
		$this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
		$this->proxies = array();
		$this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
		$this->path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : false;
		$this->secure = isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS'] == 'on') : false;
		$this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : false;
		$this->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
		$this->cli = (php_sapi_name() == 'cli');
		
		if (is_callable('apache_request_headers')) {
			
			$this->headers = apache_request_headers();
			
			if (self::$loadBalanced) {
				
				if (isset($this->headers['X-Forwarded-For'])) {
					$ips = $this->headers['X-Forwarded-For'];
					$ips = explode(', ', $ips);
					$this->ip = array_shift($ips);
					
					$this->proxies = $ips;
				}
				
				if (isset($this->headers['X-Forwarded-Proto'])) {
					$this->secure = ($this->headers['X-Forwarded-Proto'] == 'HTTPS');
				}
				
			} elseif (isset($this->headers['X-Forwarded-For'])) {
				
				$ips = $this->headers['X-Forwarded-For'];
				$ips = explode(', ', $ips);
				$this->proxies = $ips;
				
			}
		
		} else
			$this->headers = array();
			
		if ($bodyFormat == 'json') {
			
			$stream = fopen('php://stdin', 'r');
			$this->post = stream_get_contents($stream);<commit_msg>STDIN constant not working in test enviro, switching to php://input<commit_after><?PHP

namespace Firelit;

class ServerRequest {
	
	// All properties accessible via magic getter method
	private $ip, $proxies, $host, $path, $method, $secure, $referer, $cli, $headers;
	private $post, $get, $cookie;
	
	public static $loadBalanced = false;

	// $filter should be a filtering function, if supplied, which filters a string value by reference
	public function __construct($filter = false, $bodyFormat = 'querystring') { 
		
		$this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
		$this->proxies = array();
		$this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
		$this->path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : false;
		$this->secure = isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS'] == 'on') : false;
		$this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : false;
		$this->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
		$this->cli = (php_sapi_name() == 'cli');
		
		if (is_callable('apache_request_headers')) {
			
			$this->headers = apache_request_headers();
			
			if (self::$loadBalanced) {
				
				if (isset($this->headers['X-Forwarded-For'])) {
					$ips = $this->headers['X-Forwarded-For'];
					$ips = explode(', ', $ips);
					$this->ip = array_shift($ips);
					
					$this->proxies = $ips;
				}
				
				if (isset($this->headers['X-Forwarded-Proto'])) {
					$this->secure = ($this->headers['X-Forwarded-Proto'] == 'HTTPS');
				}
				
			} elseif (isset($this->headers['X-Forwarded-For'])) {
				
				$ips = $this->headers['X-Forwarded-For'];
				$ips = explode(', ', $ips);
				$this->proxies = $ips;
				
			}
		
		} else
			$this->headers = array();
			
		if ($bodyFormat == 'json') {
			
			$stream = fopen('php://input', 'r');
			$this->post = stream_get_contents($stream);
{'fraction_non_alphanumeric': 0.2006335797254488, 'fraction_numerical': 0.0, 'mean_word_length': 3.8701799485861184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '2619724', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1264, 'n_words': 254}