<commit_before><?php

namespace Clue\React\Buzz\Message;

use Clue\React\Buzz\Message\Request\Request;
use Clue\React\Buzz\Message\Response\BufferedResponse;
use Exception;
use Clue\React\Buzz\Browser;
use React\HttpClient\Client as HttpClient;

class Transaction
{
    private $browser;
    private $request;

    private $maxRedirects = 10;
    private $numRequests = 0;

    // context: http.ignore_errors
    private $obeySuccessCode = true;

    public function __construct(Request $request, Browser $browser)
    {
        $this->request = $request;
        $this->browser = $browser;
    }

    public function send($content = null)
    {
        return $this->next($this->request, $content);
    }

    protected function next(Request $request, $content = null)
    {
        $this->progress('request', array($request));

        $that = $this;
        ++$this->numRequests;

        return $request->send($this->browser->getClient(), $content)->then(
            function (BufferedResponse $response) use ($request, $that) {
                return $that->onResponse($response, $request);
            },
            function ($error) use ($request, $that) {
                return $that->onError($error, $request);
            }
        );
    }

    public function onResponse(BufferedResponse $response, Request $request)
    {
        $this->progress('response', array($response, $request));

        if ($response->getCode() >= 300 && $response->getCode() < 400 && $location = $response->getHeader('Location')) {
            // naïve approach..
            $request = new Request('GET', $location);

            $this->progress('redirect', array($request));
<commit_msg>Add option to toggle following redirects (refs #2)<commit_after><?php

namespace Clue\React\Buzz\Message;

use Clue\React\Buzz\Message\Request\Request;
use Clue\React\Buzz\Message\Response\BufferedResponse;
use Exception;
use Clue\React\Buzz\Browser;
use React\HttpClient\Client as HttpClient;

class Transaction
{
    private $browser;
    private $request;

    private $numRequests = 0;

    // context: http.follow_location
    private $followRedirects = false;

    // context: http.max_redirects
    private $maxRedirects = 10;

    // context: http.ignore_errors
    private $obeySuccessCode = true;

    public function __construct(Request $request, Browser $browser)
    {
        $this->request = $request;
        $this->browser = $browser;
    }

    public function send($content = null)
    {
        return $this->next($this->request, $content);
    }

    protected function next(Request $request, $content = null)
    {
        $this->progress('request', array($request));

        $that = $this;
        ++$this->numRequests;

        return $request->send($this->browser->getClient(), $content)->then(
            function (BufferedResponse $response) use ($request, $that) {
                return $that->onResponse($response, $request);
            },
            function ($error) use ($request, $that) {
                return $that->onError($error, $request);
            }
        );
    }

    public function onResponse(BufferedResponse $response, Request $request)
    {
        $this->progress('response', array($response, $request));

        if ($this->followRedirects && ($response->getCode() >= 300 && $response->getCode() < 400 && $location = $response->getHeader('Location'))) {
            // naïve approach..
            $request = new Request('GET', $location);

            $this->progress('redirect', array($request));

{'fraction_non_alphanumeric': 0.14430951708556905, 'fraction_numerical': 0.005365715899463428, 'mean_word_length': 2.7402323125659978, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '2732585', 'n_tokens_mistral': 1016, 'n_tokens_neox': 977, 'n_words': 223}