55 * @link http://github.com/zendframework/zf2 for the canonical source repository
66 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
77 * @license http://framework.zend.com/license/new-bsd New BSD License
8- * @package Zend_Http
98 */
109
1110namespace Zend \Http ;
1918
2019/**
2120 * Http client
22- *
23- * @category Zend
24- * @package Zend\Http
2521 */
2622class Client implements Stdlib \DispatchableInterface
2723{
@@ -113,6 +109,7 @@ class Client implements Stdlib\DispatchableInterface
113109 'keepalive ' => false ,
114110 'outputstream ' => false ,
115111 'encodecookies ' => true ,
112+ 'argseparator ' => null ,
116113 'rfc3986strict ' => false
117114 );
118115
@@ -355,6 +352,33 @@ public function getMethod()
355352 return $ this ->getRequest ()->getMethod ();
356353 }
357354
355+ /**
356+ * Set the query string argument separator
357+ *
358+ * @param string $argSeparator
359+ * @return Client
360+ */
361+ public function setArgSeparator ($ argSeparator )
362+ {
363+ $ this ->setOptions (array ("argseparator " => $ argSeparator ));
364+ return $ this ;
365+ }
366+
367+ /**
368+ * Get the query string argument separator
369+ *
370+ * @return string
371+ */
372+ public function getArgSeparator ()
373+ {
374+ $ argSeparator = $ this ->config ['argseparator ' ];
375+ if (empty ($ argSeparator )) {
376+ $ argSeparator = ini_get ('arg_separator.output ' );
377+ $ this ->setArgSeparator ($ argSeparator );
378+ }
379+ return $ argSeparator ;
380+ }
381+
358382 /**
359383 * Set the encoding type and the boundary (if any)
360384 *
@@ -469,11 +493,11 @@ public function addCookie($cookie, $value = null, $expire = null, $path = null,
469493 throw new Exception \InvalidArgumentException ('The cookie parameter is not a valid Set-Cookie type ' );
470494 }
471495 }
472- } elseif ($ cookie instanceof Header \SetCookie) {
473- $ this ->cookies [$ this ->getCookieId ($ cookie )] = $ cookie ;
474496 } elseif (is_string ($ cookie ) && $ value !== null ) {
475497 $ setCookie = new Header \SetCookie ($ cookie , $ value , $ expire , $ path , $ domain , $ secure , $ httponly , $ maxAge , $ version );
476498 $ this ->cookies [$ this ->getCookieId ($ setCookie )] = $ setCookie ;
499+ } elseif ($ cookie instanceof Header \SetCookie) {
500+ $ this ->cookies [$ this ->getCookieId ($ cookie )] = $ cookie ;
477501 } else {
478502 throw new Exception \InvalidArgumentException ('Invalid parameter type passed as Cookie ' );
479503 }
@@ -582,7 +606,7 @@ public function setStream($streamfile = true)
582606 */
583607 public function getStream ()
584608 {
585- if (! is_null ( $ this ->streamName ) ) {
609+ if (null !== $ this ->streamName ) {
586610 return $ this ->streamName ;
587611 }
588612
@@ -777,14 +801,14 @@ public function send(Request $request = null)
777801
778802 if (!empty ($ queryArray )) {
779803 $ newUri = $ uri ->toString ();
780- $ queryString = http_build_query ($ query );
804+ $ queryString = http_build_query ($ query, null , $ this -> getArgSeparator () );
781805
782806 if ($ this ->config ['rfc3986strict ' ]) {
783807 $ queryString = str_replace ('+ ' , '%20 ' , $ queryString );
784808 }
785809
786810 if (strpos ($ newUri , '? ' ) !== false ) {
787- $ newUri .= ' & ' . $ queryString ;
811+ $ newUri .= $ this -> getArgSeparator () . $ queryString ;
788812 } else {
789813 $ newUri .= '? ' . $ queryString ;
790814 }
@@ -855,9 +879,9 @@ public function send(Request $request = null)
855879 }
856880
857881 // Get the cookies from response (if any)
858- $ setCookie = $ response ->getCookie ();
859- if (!empty ($ setCookie )) {
860- $ this ->addCookie ($ setCookie );
882+ $ setCookies = $ response ->getCookie ();
883+ if (!empty ($ setCookies )) {
884+ $ this ->addCookie ($ setCookies );
861885 }
862886
863887 // If we got redirected, look for the Location header
@@ -1294,7 +1318,6 @@ protected function doRequest(Http $uri, $method, $secure = false, $headers = arr
12941318 throw new Exception \RuntimeException ('Adapter does not support streaming ' );
12951319 }
12961320 }
1297-
12981321 // HTTP connection
12991322 $ this ->lastRawRequest = $ this ->adapter ->write ($ method ,
13001323 $ uri , $ this ->config ['httpversion ' ], $ headers , $ body );
@@ -1311,7 +1334,7 @@ protected function doRequest(Http $uri, $method, $secure = false, $headers = arr
13111334 * @param string $password
13121335 * @param string $type
13131336 * @return string
1314- * @throws Zend\Http\ Client\Exception\InvalidArgumentException
1337+ * @throws Client\Exception\InvalidArgumentException
13151338 */
13161339 public static function encodeAuthHeader ($ user , $ password , $ type = self ::AUTH_BASIC )
13171340 {
0 commit comments