Permalink
Browse files

Merge pull request #599 from omeryar/dev

Set request type before setting body
  • Loading branch information...
2 parents 94ae23b + 59c1780 commit 9cb627c7da116decda115fdc27fa71b9fcd10fcd @nateabele nateabele committed Aug 2, 2012
Showing with 6 additions and 6 deletions.
  1. +1 −1 net/http/Service.php
  2. +5 −5 tests/cases/net/http/ServiceTest.php
View
@@ -216,8 +216,8 @@ protected function _request($method, $path, $data, $options) {
$request->method = $method = strtoupper($method);
$hasBody = in_array($method, array('POST', 'PUT'));
- $hasBody ? $request->body($data) : $request->query = $data;
$hasBody ? $request->type($options['type']) : null;
+ $hasBody ? $request->body($data) : $request->query = $data;
return $request;
}
}
@@ -178,15 +178,15 @@ public function testDelete() {
public function testJsonPost() {
$http = new Service($this->_testConfig);
- $http->post('update.xml', array('status' => 'cool'), array('type' => 'json'));
+ $http->post('update.xml', array('status' => array('cool', 'awesome')), array('type' => 'json'));
$expected = join("\r\n", array(
'POST /update.xml HTTP/1.1',
'Host: localhost:80',
'Connection: Close',
'User-Agent: Mozilla/5.0',
'Content-Type: application/json',
- 'Content-Length: 17',
- '', '{"status":"cool"}'
+ 'Content-Length: 29',
+ '', '{"status":["cool","awesome"]}'
));
$result = (string) $http->last->request;
$this->assertEqual($expected, $result);
@@ -197,8 +197,8 @@ public function testJsonPost() {
'Connection: Close',
'User-Agent: Mozilla/5.0',
'Content-Type: application/json',
- 'Content-Length: 17',
- '', '{"status":"cool"}'
+ 'Content-Length: 29',
+ '', '{"status":["cool","awesome"]}'
));
$result = (string) $http->last->response;
$this->assertEqual($expected, $result);

0 comments on commit 9cb627c

Please sign in to comment.