$response = Response::parse($message); expect($response->headers->cookies->data())->toBe($cookies); expect($response->toMessage())->toBe($message); }); it("decodes chunked body", function () { $headers = join("\r\n", ['HTTP/1.1 200 OK', 'Date: Mon, 22 Mar 2004 11:15:03 GMT', 'Content-Type: text/html', 'Transfer-Encoding: chunked', '', '']); $body = "29\r\n"; $body .= "<html><body><p>The file you requested is \r\n"; $body .= "6\r\n"; $body .= "3,400 \r\n"; $body .= "22\r\n"; $body .= "bytes long and was last modified: \r\n"; $body .= "1d\r\n"; $body .= "Fri, 25 Dec 2015 00:00:00 GMT\r\n"; $body .= "13\r\n"; $body .= ".</p></body></html>\r\n"; $body .= "0\r\n"; $response = Response::parse($headers . $body); $expected = <<<EOD <html><body><p>The file you requested is 3,400 bytes long and was last modified: Fri, 25 Dec 2015 00:00:00 GMT.</p></body></html> EOD; expect($response->body())->toBe($expected); }); it("throws an exception if the message can't be parsed", function () { $closure = function () { Response::parse(''); }; expect($closure)->toThrow(new NetException('The CRLFCRLF separator between headers and body is missing.')); }); }); });