<commit_before><?php
namespace phpgt\fetch;

use React\Promise\Deferred;
use React\EventLoop\LoopInterface;

/**
 * @property-read bool $bodyUsed Indicates whether the body has been read yet
 * @property-read Headers $headers Contains the Headers object associated
 * with the response
 * @property-read bool $ok Whether the response was successful (status in
 * the range 200-299) or not
 * @property-read int $status The status code of the response
 * @property-read string $statusText The status message corresponding to the
 * status code
 * @property-read string $type Type of the response (basic, cors, error
 * or opaque)
 * @property-read string $url The URL of the response
 *
 */
class Response {
use Body;

/** @var Headers */
private $headers;
private $rawHeaders = "";
private $rawBody = "";

/** @var React\Promise\Deferred[] */
private $readRawBodyDeferredArray = [];
/** @var callable[] */
private $readRawBodyDeferredTransformArray = [];

/** @var React\Promise\Deferred */
private $deferredResponse;
private $isHeaderStreaming;

public function __construct(Deferred $deferredResponse, LoopInterface $loop) {
	$this->headers = new Headers();
	$this->deferredResponse = $deferredResponse;
}

public function stream($curlHandle, string $data):int {
	$bytesRead = strlen($data);

	if(is_null($this->isHeaderStreaming)) {
		$this->isHeaderStreaming = true;
	}

	if($this->isHeaderStreaming) {
		$this->rawHeaders .= $data;
		$this->isHeaderStreaming = $this->setHeaders($data);

		if(!$this->isHeaderStreaming) {
			$this->deferredResponse->resolve($this);<commit_msg>Respond with correct HTTP status code<commit_after><?php
namespace phpgt\fetch;

use React\Promise\Deferred;
use React\EventLoop\LoopInterface;
use PHPCurl\CurlWrapper\Curl;

/**
 * @property-read bool $bodyUsed Indicates whether the body has been read yet
 * @property-read Headers $headers Contains the Headers object associated
 * with the response
 * @property-read bool $ok Whether the response was successful (status in
 * the range 200-299) or not
 * @property-read int $status The status code of the response
 * @property-read string $statusText The status message corresponding to the
 * status code
 * @property-read string $type Type of the response (basic, cors, error
 * or opaque)
 * @property-read string $url The URL of the response
 *
 */
class Response {
use Body;

/** @var Headers */
private $headers;
private $rawHeaders = "";
private $rawBody = "";
private $curlInfo;

/** @var React\Promise\Deferred[] */
private $readRawBodyDeferredArray = [];
/** @var callable[] */
private $readRawBodyDeferredTransformArray = [];

/** @var React\Promise\Deferred */
private $deferredResponse;
private $isHeaderStreaming;

public function __construct(Deferred $deferredResponse, LoopInterface $loop) {
	$this->headers = new Headers();
	$this->deferredResponse = $deferredResponse;
}

public function __get($name) {
	switch($name) {
	case "status":
		return (int)$this->curlInfo["http_code"];

	case "info":
		return $this->curlInfo;
	}
}

public function stream($curlHandle, string $data):int {
	$bytesRead = strlen($data);

	if(is_null($this->isHeaderStreaming)) {
		$this->isHeaderStreaming = true;
	}

	if($this->isHeaderStreaming) {
		$this->rawHeaders .= $data;
		$this->isHeaderStreaming = $this->setHeaders($data);

		if(!$this->isHeaderStreaming) {
			$this->curlInfo = curl_getinfo($curlHandle);
			$this->deferredResponse->resolve($this);
{'fraction_non_alphanumeric': 0.13176265270506107, 'fraction_numerical': 0.0034904013961605585, 'mean_word_length': 5.065255731922399, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 28, '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': '6671201', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1022, 'n_words': 298}