<commit_before><?php
namespace Niysu\Filters;

/**
 * Handles content-encoding as request by the client.
 *
 * @copyright 	2012 <NAME> <<EMAIL>>
 * @license 	MIT http://opensource.org/licenses/MIT
 * @link 		http://github.com/Tomaka17/niysu
 */
class ContentEncodingResponseFilter extends \Niysu\HTTPResponseFilterInterface {
	public function __construct(\Niysu\HTTPResponseInterface $next, \Niysu\HTTPRequestInterface $request) {
		parent::__construct($next);

		$encodingUsed = $request->getHighestPriorityForEncoding('gzip', 'deflate', 'bzip2', 'identity');
		if (empty($encodingUsed))
			$encodingUsed = 'identity';
		$this->setEncodingToUse($encodingUsed);
	}

	public function appendData($data) {
		$this->data .= $data;
	}

	public function flush() {
		parent::appendData(call_user_func($this->compressFunction, $this->data));
		parent::flush();
	}

	public function setHeader($header, $value) {
		if ($header == 'Content-Encoding')
			$this->compressFunction = function($data) { return $data; };
		parent::setHeader($header, $value);
	}

	public function addHeader($header, $value) {
		if ($header == 'Content-Encoding')
			$this->compressFunction = function($data) { return $data; };
		parent::addHeader($header, $value);
	}
<commit_msg>ContentEncodingResponseFilter no longer tries to use bzip2 if extension is not installed<commit_after><?php
namespace Niysu\Filters;

/**
 * Handles content-encoding as request by the client.
 *
 * Supported encoding: gzip, deflate, bzip2 (if extension is installed).
 *
 * @copyright 	2012 <NAME> <<EMAIL>>
 * @license 	MIT http://opensource.org/licenses/MIT
 * @link 		http://github.com/Tomaka17/niysu
 */
class ContentEncodingResponseFilter extends \Niysu\HTTPResponseFilterInterface {
	public function __construct(\Niysu\HTTPResponseInterface $next, \Niysu\HTTPRequestInterface $request) {
		parent::__construct($next);

		// computing the list of encodings supported by the server
		$availableEncodings = [ 'gzip', 'deflate', 'identity' ];
		if (function_exists('bzcompress'))
			$availableEncodings = array_splice($availableEncodings, 2, 0, 'bzip2');

		// determining the encoding to use
		$encodingUsed = call_user_func_array([ $request, 'getHighestPriorityForEncoding' ], $availableEncodings);
		if (empty($encodingUsed))
			$encodingUsed = 'identity';
		$this->setEncodingToUse($encodingUsed);
	}

	public function appendData($data) {
		$this->data .= $data;
	}

	public function flush() {
		parent::appendData(call_user_func($this->compressFunction, $this->data));
		parent::flush();
	}

	public function setHeader($header, $value) {
		if ($header == 'Content-Encoding')
			$this->compressFunction = function($data) { return $data; };
		parent::setHeader($header, $value);
	}

	public function addHeader($header, $value) {
		if ($header == 'Content-Encoding')
			$this->compressFunction = function($data) { return $data; };
		parent::addHeader($header, $value);
	}

{'fraction_non_alphanumeric': 0.14989733059548255, 'fraction_numerical': 0.006160164271047228, 'mean_word_length': 5.340563991323211, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, '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': '410371', 'n_tokens_mistral': 964, 'n_tokens_neox': 895, 'n_words': 199}