<commit_before><?php

namespace Hochstrasser\Wirecard;

use Psr\Http\Message\RequestInterface;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7;

abstract class Adapter
{
    static function defaultAdapter()
    {
        return function (RequestInterface $request) {
            $headers = [];

            foreach ($request->getHeaders() as $header => $values) {
                $headers[] = $header.': '.implode(',', $values);
            }

            $streamContext = stream_context_create([
                'http' => [
                    'method' => $request->getMethod(),
                    'header' => $headers,
                    'content' => Psr7\copy_to_string($request->getBody()),
                    'protocol_version' => $request->getProtocolVersion()
                ]
            ]);

            $stream = fopen((string) $request->getUri(), 'r', false, $streamContext);
            $responseBody = stream_get_contents($stream);
            $metadata = stream_get_meta_data($stream);
            fclose($stream);

            $response = new Response(200, [], $responseBody);

            return $response;
        };
    }
}<commit_msg>Handle response status and headers in default adapter<commit_after><?php

namespace Hochstrasser\Wirecard;

use Psr\Http\Message\RequestInterface;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7;

abstract class Adapter
{
    static function defaultAdapter()
    {
        return function (RequestInterface $request) {
            $headers = [];

            foreach ($request->getHeaders() as $header => $values) {
                $headers[] = $header.': '.implode(',', $values);
            }

            $streamContext = stream_context_create([
                'http' => [
                    'method' => $request->getMethod(),
                    'header' => $headers,
                    'content' => Psr7\copy_to_string($request->getBody()),
                    'protocol_version' => $request->getProtocolVersion()
                ]
            ]);

            $stream = fopen((string) $request->getUri(), 'r', false, $streamContext);
            $responseBody = stream_get_contents($stream);
            fclose($stream);
            $headers = [];

            $statusLine = $http_response_header[0];

            preg_match('{^HTTP/([0-9\.]+) (\d+) (.+)$}', $statusLine, $matches);

            $version = $matches[1];
            $status = $matches[2];
            $reason = $matches[3];

            foreach (array_slice($http_response_header, 1) as $headerLine) {
                list($header, $value) = explode(':', $headerLine);
                $headers[$header] = explode(';', $value);
            }

            $response = new Response($status, $headers, $responseBody, $version, $reason);

            return $response;
        };
    }
}
{'fraction_non_alphanumeric': 0.14726756564939675, 'fraction_numerical': 0.0056777856635912, 'mean_word_length': 1.9518324607329842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '4177368', 'n_tokens_mistral': 785, 'n_tokens_neox': 745, 'n_words': 147}