public function send($method, $path = null, $data = array(), $options = array()) { $defaults = array('return' => 'body', 'type' => 'form'); $options += $defaults; $request = $this->_request($method, $path, $data, $options); $response = new Response(); $response->body = json_encode(array('ok' => true, 'id' => '12345', 'rev' => '1-2', 'body' => 'something')); $this->last = (object) compact('request', 'response'); return $options['return'] == 'body' ? $response->body() : $response; }
public function testMessageWithNoHeaders() { $body = "\n<html>...</html>\n"; $message = "\r\n\r\n{$body}"; $response = new Response(compact('message')); $this->assertEmpty($response->headers()); $this->assertEqual(trim($body), $response->body()); }
function testTransferEncodingChunkedDecode() { $headers = join("\r\n", array('HTTP/1.1 200 OK', 'Server: CouchDB/0.10.0 (Erlang OTP/R13B)', 'Etag: "DWGTHR79JLSOGACPLVIZBJUBP"', 'Date: Wed, 11 Nov 2009 19:49:41 GMT', 'Content-Type: text/plain;charset=utf-8', 'Cache-Control: must-revalidate', 'Transfer-Encoding: chunked', 'Connection: Keep-alive', '', '')); $message = $headers . join("\r\n", array('b7', '{"total_rows":1,"offset":0,"rows":[', '{"id":"88989cafcd81b09f81078eb523832e8e","key":"gwoo","value":' . '{"author":"gwoo","language":"php","preview":"test",' . '"created":"2009-10-27 12:14:12"}}', '4', '', ']}', '1', '', '', '0', '', '')); $response = new Response(compact('message')); $expected = join("\r\n", array('{"total_rows":1,"offset":0,"rows":[', '{"id":"88989cafcd81b09f81078eb523832e8e","key":"gwoo","value":' . '{"author":"gwoo","language":"php","preview":"test",' . '"created":"2009-10-27 12:14:12"}}', ']}')); $this->assertEqual($expected, $response->body()); $message = $headers . join("\r\n", array('body')); $response = new Response(compact('message')); $result = $response->body(); $this->assertEqual('body', $result); $message = $headers . join("\r\n", array('[part one];', '[part two]')); $expected = '[part two]'; $response = new Response(compact('message')); $result = $response->body(); $this->assertEqual($expected, $result); $message = join("\r\n", array('HTTP/1.1 200 OK', 'Header: Value', 'Connection: close', 'Content-Type: text/html;charset=UTF-8', 'Transfer-Encoding: text', '', 'Test!')); $expected = 'Test!'; $response = new Response(compact('message')); $result = $response->body(); $this->assertEqual($expected, $result); }