Skip to content

Commit

Permalink
Rename content() -> body()
Browse files Browse the repository at this point in the history
This makes methods & terms consistent between requests/responses.
  • Loading branch information
markstory committed Dec 28, 2012
1 parent 0d63455 commit 34a1106
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Network/Http/Client.php
Expand Up @@ -278,15 +278,15 @@ public function buildUrl($url, $query = [], $options = []) {
*
* @param string $method HTTP method name.
* @param string $url The url including query string.
* @param mixed $data The request body content.
* @param mixed $data The request body.
* @param array $options The options to use. Contains auth, proxy etc.
* @return Cake\Network\Http\Request
*/
protected function _createRequest($method, $url, $data, $options) {
$request = new Request();
$request->method($method)
->url($url)
->content($data);
->body($data);
if (isset($options['type'])) {
$request->header($this->_typeHeaders($options['type']));
}
Expand Down
38 changes: 38 additions & 0 deletions lib/Cake/Network/Http/Message.php
Expand Up @@ -45,6 +45,12 @@ class Message {
*/
protected $_cookies;

/**
* HTTP Version being used.
*
* @var string
*/
protected $_version = '1.1';

/**
* Normalize header names to Camel-Case form.
Expand All @@ -59,4 +65,36 @@ protected function _normalizeHeader($name) {
return implode('-', $parts);
}

/**
* Get all cookies
*
* @return array
*/
public function cookies() {
return $this->_cookies;
}

/**
* Get the HTTP version used.
*
* @return string
*/
public function version() {
return $this->_version;
}

/**
* Get/set the body for the message.
*
* @param string|null $body The body for the request. Leave null for get
* @return mixed Either $this or the body value.
*/
public function body($body = null) {
if ($body === null) {
return $this->_body;
}
$this->_body = $body;
return $this;
}

}
36 changes: 1 addition & 35 deletions lib/Cake/Network/Http/Request.php
Expand Up @@ -24,16 +24,9 @@
*/
class Request extends Message {

/**
* HTTP Version being used.
*
* @var string
*/
protected $_version = '1.1';

protected $_method;

protected $_content;
protected $_body;

protected $_url;

Expand Down Expand Up @@ -126,20 +119,6 @@ public function headers() {
return $this->_headers;
}

/**
* Get/set the content or body for the request.
*
* @param string|null $content The content for the request. Leave null for get
* @return mixed Either $this or the content value.
*/
public function content($content = null) {
if ($content === null) {
return $this->_content;
}
$this->_content = $content;
return $this;
}

/**
* Get/Set cookie values.
*
Expand Down Expand Up @@ -172,17 +151,4 @@ public function cookie($name, $value = null) {
return $this;
}

/**
* Get all cookies
*
* @return array
*/
public function cookies() {
return $this->_cookies;
}

public function version() {
return $this->_version;
}

}
1 change: 1 addition & 0 deletions lib/Cake/Network/Http/Response.php
Expand Up @@ -86,6 +86,7 @@ class Response extends Message implements \ArrayAccess {
'body' => '_body',
'code' => '_code'
];

/**
* Constructor
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/TestCase/Network/Http/ClientTest.php
Expand Up @@ -222,7 +222,7 @@ public function testGetWithContent() {
$this->isInstanceOf('Cake\Network\Http\Request'),
$this->attributeEqualTo('_method', Request::METHOD_GET),
$this->attributeEqualTo('_url', 'http://cakephp.org/search'),
$this->attributeEqualTo('_content', 'some data')
$this->attributeEqualTo('_body', 'some data')
))
->will($this->returnValue($response));

Expand Down Expand Up @@ -312,7 +312,7 @@ public function testPostWithTypeKey($type, $mime) {
->method('send')
->with($this->logicalAnd(
$this->attributeEqualTo('_method', Request::METHOD_POST),
$this->attributeEqualTo('_content', $data),
$this->attributeEqualTo('_body', $data),
$this->attributeEqualTo('_headers', $headers)
))
->will($this->returnValue($response));
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Test/TestCase/Network/Http/RequestTest.php
Expand Up @@ -57,16 +57,16 @@ public function testMethodInvalid() {
}

/**
* test content method.
* test body method.
*
* @return void
*/
public function testContent() {
public function testBody() {
$data = '{"json":"data"}';
$request = new Request();
$this->assertSame($request, $request->content($data));
$this->assertSame($request, $request->body($data));

$this->assertEquals($data, $request->content());
$this->assertEquals($data, $request->body());
}

/**
Expand Down

0 comments on commit 34a1106

Please sign in to comment.