From 64764fb9fac0227f8e0443e7c7519d73aec275b9 Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 14:58:55 -0300 Subject: Initial import --- tests/StreamTransport.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/StreamTransport.php (limited to 'tests/StreamTransport.php') diff --git a/tests/StreamTransport.php b/tests/StreamTransport.php new file mode 100644 index 0000000..174e516 --- /dev/null +++ b/tests/StreamTransport.php @@ -0,0 +1,52 @@ + $value) { + $lines .= $name . ': ' . $value . "\r\n"; + } + + $context = stream_context_create(['http' => [ + 'method' => 'GET', + 'header' => $lines, + 'timeout' => $timeout, + 'ignore_errors' => true, + ]]); + + $body = @file_get_contents($url, false, $context); + if ($body === false) { + throw new NetworkException('could not reach ' . $url); + } + + $status = 0; + $received = []; + foreach ($http_response_header ?? [] as $line) { + if (preg_match('#^HTTP/\S+\s+(\d{3})#', $line, $match) === 1) { + $status = (int) $match[1]; + continue; + } + $parts = explode(':', $line, 2); + if (count($parts) === 2) { + $received[trim($parts[0])][] = trim($parts[1]); + } + } + + return new Response($status, $received, $body); + } +} -- cgit v1.3