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

File tree

12 files changed

+231
-48
lines changed

12 files changed

+231
-48
lines changed

src/Client.php

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function getLastRawResponse()
282282
/**
283283
* Get the redirections count
284284
*
285-
* @return integer
285+
* @return int
286286
*/
287287
public function getRedirectionsCount()
288288
{
@@ -298,8 +298,18 @@ public function getRedirectionsCount()
298298
public function setUri($uri)
299299
{
300300
if (!empty($uri)) {
301+
// remember host of last request
302+
$lastHost = $this->getRequest()->getUri()->getHost();
301303
$this->getRequest()->setUri($uri);
302304

305+
// if host changed, the HTTP authentication should be cleared for security
306+
// reasons, see #4215 for a discussion - currently authentication is also
307+
// cleared for peer subdomains due to technical limits
308+
$nextHost = $this->getRequest()->getUri()->getHost();
309+
if (!preg_match('/' . preg_quote($lastHost, '/') . '$/i', $nextHost)) {
310+
$this->clearAuth();
311+
}
312+
303313
// Set auth if username and password has been specified in the uri
304314
if ($this->getUri()->getUser() && $this->getUri()->getPassword()) {
305315
$this->setAuth($this->getUri()->getUser(), $this->getUri()->getPassword());
@@ -444,6 +454,37 @@ public function setParameterGet(array $query)
444454
return $this;
445455
}
446456

457+
/**
458+
* Reset all the HTTP parameters (request, response, etc)
459+
*
460+
* @param bool $clearCookies Also clear all valid cookies? (defaults to false)
461+
* @param bool $clearAuth Also clear http authentication? (defaults to true)
462+
* @return Client
463+
*/
464+
public function resetParameters($clearCookies = false, $clearAuth = true)
465+
{
466+
$uri = $this->getUri();
467+
468+
$this->streamName = null;
469+
$this->encType = null;
470+
$this->request = null;
471+
$this->response = null;
472+
$this->lastRawRequest = null;
473+
$this->lastRawResponse = null;
474+
475+
$this->setUri($uri);
476+
477+
if ($clearCookies) {
478+
$this->clearCookies();
479+
}
480+
481+
if ($clearAuth) {
482+
$this->clearAuth();
483+
}
484+
485+
return $this;
486+
}
487+
447488
/**
448489
* Return the current cookies
449490
*
@@ -673,6 +714,14 @@ public function setAuth($user, $password, $type = self::AUTH_BASIC)
673714
return $this;
674715
}
675716

717+
/**
718+
* Clear http authentication
719+
*/
720+
public function clearAuth()
721+
{
722+
$this->auth = array();
723+
}
724+
676725
/**
677726
* Calculate the response value according to the HTTP authentication type
678727
*
@@ -728,31 +777,6 @@ protected function calcAuthDigest($user, $password, $type = self::AUTH_BASIC, $d
728777
return $response;
729778
}
730779

731-
/**
732-
* Reset all the HTTP parameters (auth,cookies,request, response, etc)
733-
*
734-
* @param bool $clearCookies Also clear all valid cookies? (defaults to false)
735-
* @return Client
736-
*/
737-
public function resetParameters($clearCookies = false)
738-
{
739-
$uri = $this->getUri();
740-
741-
$this->auth = null;
742-
$this->streamName = null;
743-
$this->encType = null;
744-
$this->request = null;
745-
$this->response = null;
746-
747-
$this->setUri($uri);
748-
749-
if ($clearCookies) {
750-
$this->clearCookies();
751-
}
752-
753-
return $this;
754-
}
755-
756780
/**
757781
* Dispatch
758782
*
@@ -897,13 +921,15 @@ public function send(Request $request = null)
897921
((! $this->config['strictredirects']) && ($response->getStatusCode() == 302 ||
898922
$response->getStatusCode() == 301))) {
899923

900-
$this->resetParameters();
924+
$this->resetParameters(false, false);
901925
$this->setMethod(Request::METHOD_GET);
902926
}
903927

928+
904929
// If we got a well formed absolute URI
905930
if (($scheme = substr($location, 0, 6)) &&
906931
($scheme == 'http:/' || $scheme == 'https:')) {
932+
// setURI() clears parameters if host changed, see #4215
907933
$this->setUri($location);
908934
} else {
909935

@@ -933,12 +959,26 @@ public function send(Request $request = null)
933959
break;
934960
}
935961

936-
} while ($this->redirectCounter < $this->config['maxredirects']);
962+
} while ($this->redirectCounter <= $this->config['maxredirects']);
937963

938964
$this->response = $response;
939965
return $response;
940966
}
941967

968+
/**
969+
* Fully reset the HTTP client (auth, cookies, request, response, etc.)
970+
*
971+
* @return Client
972+
*/
973+
public function reset()
974+
{
975+
$this->resetParameters();
976+
$this->clearAuth();
977+
$this->clearCookies();
978+
979+
return $this;
980+
}
981+
942982
/**
943983
* Set a file to upload (using a POST request)
944984
*
@@ -1004,7 +1044,7 @@ public function removeFileUpload($filename)
10041044
*
10051045
* @param string $domain
10061046
* @param string $path
1007-
* @param boolean $secure
1047+
* @param bool $secure
10081048
* @return Header\Cookie|bool
10091049
*/
10101050
protected function prepareCookies($domain, $path, $secure)

src/Client/Adapter/Proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function write($method, $uri, $httpVer = '1.1', $headers = array(), $body
192192
* Preform handshaking with HTTPS proxy using CONNECT method
193193
*
194194
* @param string $host
195-
* @param integer $port
195+
* @param int $port
196196
* @param string $httpVer
197197
* @param array $headers
198198
* @throws AdapterException\RuntimeException

src/Client/Adapter/Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Test implements AdapterInterface
4141
/**
4242
* Current position in the response buffer
4343
*
44-
* @var integer
44+
* @var int
4545
*/
4646
protected $responseIndex = 0;
4747

@@ -199,7 +199,7 @@ public function addResponse($response)
199199
* Sets the position of the response buffer. Selects which
200200
* response will be returned on the next call to read().
201201
*
202-
* @param integer $index
202+
* @param int $index
203203
* @throws Exception\OutOfRangeException
204204
*/
205205
public function setResponseIndex($index)

src/Header/AbstractAccept.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ protected function sortFieldValueParts()
419419
}
420420

421421
// Asterisks
422-
$values = array('type', 'subtype','format');
422+
$values = array('type', 'subtype', 'format');
423423
foreach ($values as $value) {
424424
if ($a->$value == '*' && $b->$value != '*') {
425425
return 1;

src/Header/AbstractLocation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
namespace Zend\Http\Header;
1111

1212
use Zend\Uri\Exception as UriException;
13-
use Zend\Uri\UriInterface;
14-
use Zend\Uri\UriFactory;
1513
use Zend\Uri\Uri;
14+
use Zend\Uri\UriFactory;
15+
use Zend\Uri\UriInterface;
1616

1717

1818
/**

src/Header/Accept.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
namespace Zend\Http\Header;
11-
use Zend\Http\Header\Accept\FieldValuePart;
1211

12+
use Zend\Http\Header\Accept\FieldValuePart;
1313

1414
/**
1515
* Accept Header

src/Header/AcceptCharset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
namespace Zend\Http\Header;
11+
1112
use Zend\Http\Header\Accept\FieldValuePart;
1213

1314
/**

src/Header/AcceptEncoding.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
namespace Zend\Http\Header;
11+
1112
use Zend\Http\Header\Accept\FieldValuePart;
1213

1314
/**

src/Header/AcceptLanguage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
namespace Zend\Http\Header;
11-
use Zend\Http\Header\Accept\FieldValuePart;
1211

12+
use Zend\Http\Header\Accept\FieldValuePart;
1313

1414
/**
1515
* Accept Language Header

src/Header/SetCookie.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class SetCookie implements MultipleHeaderInterface
3737
/**
3838
* Version
3939
*
40-
* @var integer
40+
* @var int
4141
*/
4242
protected $version = null;
4343

4444
/**
4545
* Max Age
4646
*
47-
* @var integer
47+
* @var int
4848
*/
4949
protected $maxAge = null;
5050

@@ -317,7 +317,7 @@ public function getValue()
317317
/**
318318
* Set version
319319
*
320-
* @param integer $version
320+
* @param int $version
321321
* @throws Exception\InvalidArgumentException
322322
*/
323323
public function setVersion($version)
@@ -331,7 +331,7 @@ public function setVersion($version)
331331
/**
332332
* Get version
333333
*
334-
* @return integer
334+
* @return int
335335
*/
336336
public function getVersion()
337337
{
@@ -341,7 +341,7 @@ public function getVersion()
341341
/**
342342
* Set Max-Age
343343
*
344-
* @param integer $maxAge
344+
* @param int $maxAge
345345
* @throws Exception\InvalidArgumentException
346346
*/
347347
public function setMaxAge($maxAge)
@@ -355,7 +355,7 @@ public function setMaxAge($maxAge)
355355
/**
356356
* Get Max-Age
357357
*
358-
* @return integer
358+
* @return int
359359
*/
360360
public function getMaxAge()
361361
{
@@ -512,9 +512,9 @@ public function isValidForRequest($requestDomain, $path, $isSecure = false)
512512
* Checks whether the cookie should be sent or not in a specific scenario
513513
*
514514
* @param string|Zend\Uri\Uri $uri URI to check against (secure, domain, path)
515-
* @param boolean $matchSessionCookies Whether to send session cookies
515+
* @param bool $matchSessionCookies Whether to send session cookies
516516
* @param int $now Override the current time when checking for expiry time
517-
* @return boolean
517+
* @return bool
518518
*/
519519
public function match($uri, $matchSessionCookies = true, $now = null)
520520
{
@@ -554,7 +554,7 @@ public function match($uri, $matchSessionCookies = true, $now = null)
554554
* @param string $cookieDomain
555555
* @param string $host
556556
*
557-
* @return boolean
557+
* @return bool
558558
*/
559559
public static function matchCookieDomain($cookieDomain, $host)
560560
{
@@ -580,7 +580,7 @@ public static function matchCookieDomain($cookieDomain, $host)
580580
*
581581
* @param string $cookiePath
582582
* @param string $path
583-
* @return boolean
583+
* @return bool
584584
*/
585585
public static function matchCookiePath($cookiePath, $path)
586586
{

0 commit comments

Comments
 (0)