Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/2774' into develop
Browse files Browse the repository at this point in the history
Close #2774
Close #2745
  • Loading branch information
weierophinney committed Nov 9, 2012
2 parents c59ec4d + 7b3da41 commit 58dde55
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
32 changes: 30 additions & 2 deletions library/Zend/Http/Client.php
Expand Up @@ -113,6 +113,7 @@ class Client implements Stdlib\DispatchableInterface
'keepalive' => false, 'keepalive' => false,
'outputstream' => false, 'outputstream' => false,
'encodecookies' => true, 'encodecookies' => true,
'argseparator' => null,
'rfc3986strict' => false 'rfc3986strict' => false
); );


Expand Down Expand Up @@ -355,6 +356,33 @@ public function getMethod()
return $this->getRequest()->getMethod(); return $this->getRequest()->getMethod();
} }


/**
* Set the query string argument separator
*
* @param string $argSeparator
* @return Client
*/
public function setArgSeparator($argSeparator)
{
$this->setOptions(array("argseparator" => $argSeparator));
return $this;
}

/**
* Get the query string argument separator
*
* @return string
*/
public function getArgSeparator()
{
$argSeparator = $this->config['argseparator'];
if (empty($argSeparator)) {
$argSeparator = ini_get('arg_separator.output');
$this->setArgSeparator($argSeparator);
}
return $argSeparator;
}

/** /**
* Set the encoding type and the boundary (if any) * Set the encoding type and the boundary (if any)
* *
Expand Down Expand Up @@ -773,14 +801,14 @@ public function send(Request $request = null)


if (!empty($queryArray)) { if (!empty($queryArray)) {
$newUri = $uri->toString(); $newUri = $uri->toString();
$queryString = http_build_query($query); $queryString = http_build_query($query, null, $this->getArgSeparator());


if ($this->config['rfc3986strict']) { if ($this->config['rfc3986strict']) {
$queryString = str_replace('+', '%20', $queryString); $queryString = str_replace('+', '%20', $queryString);
} }


if (strpos($newUri, '?') !== false) { if (strpos($newUri, '?') !== false) {
$newUri .= '&' . $queryString; $newUri .= $this->getArgSeparator() . $queryString;
} else { } else {
$newUri .= '?' . $queryString; $newUri .= '?' . $queryString;
} }
Expand Down
42 changes: 32 additions & 10 deletions tests/ZendTest/Http/Client/CommonHttpTests.php
Expand Up @@ -113,20 +113,28 @@ protected function tearDown()
* Simple request tests * Simple request tests
*/ */


public function methodProvider()
{
return array(
array(Request::METHOD_GET),
array(Request::METHOD_POST),
array(Request::METHOD_OPTIONS),
array(Request::METHOD_PUT),
array(Request::METHOD_DELETE),
array(Request::METHOD_PATCH),
);
}

/** /**
* Test simple requests * Test simple requests
* *
* @dataProvider methodProvider
*/ */
public function testSimpleRequests() public function testSimpleRequests($method)
{ {
$methods= array(Request::METHOD_GET, Request::METHOD_POST, Request::METHOD_OPTIONS, $this->client->setMethod($method);
Request::METHOD_PUT, Request::METHOD_DELETE, Request::METHOD_PATCH); $res = $this->client->send();

$this->assertTrue($res->isSuccess(), "HTTP {$method} request failed.");
foreach ($methods as $method) {
$this->client->setMethod($method);
$res = $this->client->send();
$this->assertTrue($res->isSuccess(), "HTTP {$method} request failed.");
}
} }


/** /**
Expand Down Expand Up @@ -977,6 +985,21 @@ public function testContentTypeAdditionlInfo($params)
$request->getHeaders()->get('Content-Type')->getFieldValue()); $request->getHeaders()->get('Content-Type')->getFieldValue());
} }


/**
* @group 2774
* @group 2745
*/
public function testUsesProvidedArgSeparator()
{
$this->client->setArgSeparator(';');
$request = new Request();
$request->setUri('http://framework.zend.com');
$request->setQuery(array('foo' => 'bar', 'baz' => 'bat'));
$this->client->send($request);
$rawRequest = $this->client->getLastRawRequest();
$this->assertContains('?foo=bar;baz=bat', $rawRequest);
}

/** /**
* Internal helpder function to get the contents of test files * Internal helpder function to get the contents of test files
* *
Expand Down Expand Up @@ -1045,5 +1068,4 @@ public static function invalidConfigProvider()
array(55) array(55)
); );
} }

} }
22 changes: 22 additions & 0 deletions tests/ZendTest/Http/ClientTest.php
Expand Up @@ -79,4 +79,26 @@ public function testIfArrayIteratorOfHeadersCanBeSet()
$cookies = $client->getCookies(); $cookies = $client->getCookies();
$this->assertEquals(2, count($cookies)); $this->assertEquals(2, count($cookies));
} }

/**
* @group 2774
* @group 2745
*/
public function testArgSeparatorDefaultsToIniSetting()
{
$argSeparator = ini_get('arg_separator.output');
$client = new Client();
$this->assertEquals($argSeparator, $client->getArgSeparator());
}

/**
* @group 2774
* @group 2745
*/
public function testCanOverrideArgSeparator()
{
$client = new Client();
$client->setArgSeparator(';');
$this->assertEquals(';', $client->getArgSeparator());
}
} }

0 comments on commit 58dde55

Please sign in to comment.