mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Making the cookies independent for each host.
This commit is contained in:
parent
eeafb55d31
commit
d332f0624f
2 changed files with 56 additions and 4 deletions
|
@ -263,10 +263,21 @@ class HttpSocket extends CakeSocket {
|
|||
}
|
||||
$request['uri'] = $this->url($request['uri']);
|
||||
$request['uri'] = $this->_parseUri($request['uri'], true);
|
||||
$this->request = Set::merge($this->request, $this->config['request'], $request);
|
||||
$this->request = Set::merge($this->request, array_diff_key($this->config['request'], array('cookies' => true)), $request);
|
||||
|
||||
$this->_configUri($this->request['uri']);
|
||||
|
||||
$Host = $this->request['uri']['host'];
|
||||
if (!empty($this->config['request']['cookies'][$Host])) {
|
||||
if (!isset($this->request['cookies'])) {
|
||||
$this->request['cookies'] = array();
|
||||
}
|
||||
if (!isset($request['cookies'])) {
|
||||
$request['cookies'] = array();
|
||||
}
|
||||
$this->request['cookies'] = array_merge($this->request['cookies'], $this->config['request']['cookies'][$Host], $request['cookies']);
|
||||
}
|
||||
|
||||
if (isset($host)) {
|
||||
$this->config['host'] = $host;
|
||||
}
|
||||
|
@ -280,7 +291,6 @@ class HttpSocket extends CakeSocket {
|
|||
if (!empty($this->request['cookies'])) {
|
||||
$cookies = $this->buildCookies($this->request['cookies']);
|
||||
}
|
||||
$Host = $this->request['uri']['host'];
|
||||
$schema = '';
|
||||
$port = 0;
|
||||
if (isset($this->request['uri']['schema'])) {
|
||||
|
@ -374,7 +384,10 @@ class HttpSocket extends CakeSocket {
|
|||
|
||||
$this->response = $this->_parseResponse($response);
|
||||
if (!empty($this->response['cookies'])) {
|
||||
$this->config['request']['cookies'] = array_merge($this->config['request']['cookies'], $this->response['cookies']);
|
||||
if (!isset($this->config['request']['cookies'][$Host])) {
|
||||
$this->config['request']['cookies'][$Host] = array();
|
||||
}
|
||||
$this->config['request']['cookies'][$Host] = array_merge($this->config['request']['cookies'][$Host], $this->response['cookies']);
|
||||
}
|
||||
|
||||
return $this->response['body'];
|
||||
|
|
|
@ -618,7 +618,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
)
|
||||
);
|
||||
$this->assertEqual($result, $expect);
|
||||
$this->assertEqual($this->Socket->config['request']['cookies'], $expect);
|
||||
$this->assertEqual($this->Socket->config['request']['cookies']['www.cakephp.org'], $expect);
|
||||
$this->assertFalse($this->Socket->connected);
|
||||
}
|
||||
|
||||
|
@ -666,6 +666,45 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$this->assertEqual($result, '<h1>This is a test!</h1>');
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestWithCrossCookie
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequestWithCrossCookie() {
|
||||
$this->Socket->connected = true;
|
||||
$this->Socket->config['request']['cookies'] = array();
|
||||
|
||||
$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
$expected = array('www.cakephp.org' => array('foo' => array('value' => 'bar')));
|
||||
$this->Socket->request('http://www.cakephp.org/');
|
||||
$this->assertEqual($this->Socket->config['request']['cookies'], $expected);
|
||||
|
||||
$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: bar=foo\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
$this->Socket->request('http://www.cakephp.org/other');
|
||||
$this->assertEqual($this->Socket->request['cookies'], array('foo' => array('value' => 'bar')));
|
||||
$expected['www.cakephp.org'] += array('bar' => array('value' => 'foo'));
|
||||
$this->assertEqual($this->Socket->config['request']['cookies'], $expected);
|
||||
|
||||
$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
$this->Socket->request('/other2');
|
||||
$this->assertEqual($this->Socket->config['request']['cookies'], $expected);
|
||||
|
||||
$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foobar=ok\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
$this->Socket->request('http://www.cake.com');
|
||||
$this->assertTrue(empty($this->Socket->request['cookies']));
|
||||
$expected['www.cake.com'] = array('foobar' => array('value' => 'ok'));
|
||||
$this->assertEqual($this->Socket->config['request']['cookies'], $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testProxy method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue