mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-29 05:02:58 +00:00
Test for new HEAD function inside HttpSocket
This commit is contained in:
parent
ad4dbdcee5
commit
0eaf650d9f
4 changed files with 76 additions and 13 deletions
lib/Cake
0
lib/Cake/Network/CakeSocket.php
Executable file → Normal file
0
lib/Cake/Network/CakeSocket.php
Executable file → Normal file
39
lib/Cake/Network/Http/HttpSocket.php
Executable file → Normal file
39
lib/Cake/Network/Http/HttpSocket.php
Executable file → Normal file
|
@ -463,6 +463,32 @@ class HttpSocket extends CakeSocket {
|
||||||
return $this->request($request);
|
return $this->request($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issues a HEAD request to the specified URI, query, and request.
|
||||||
|
*
|
||||||
|
* By definition HEAD request are identical to GET request except they return no response body. This means that all
|
||||||
|
* information and examples relevant to GET also applys to HEAD.
|
||||||
|
*
|
||||||
|
* @param string|array $uri URI to request. Either a string uri, or a uri array, see HttpSocket::_parseUri()
|
||||||
|
* @param array $query Querystring parameters to append to URI
|
||||||
|
* @param array $request An indexed array with indexes such as 'method' or uri
|
||||||
|
* @return mixed Result of request, either false on failure or the response to the request.
|
||||||
|
*/
|
||||||
|
public function head($uri = null, $query = array(), $request = array()) {
|
||||||
|
if (!empty($query)) {
|
||||||
|
$uri = $this->_parseUri($uri, $this->config['request']['uri']);
|
||||||
|
if (isset($uri['query'])) {
|
||||||
|
$uri['query'] = array_merge($uri['query'], $query);
|
||||||
|
} else {
|
||||||
|
$uri['query'] = $query;
|
||||||
|
}
|
||||||
|
$uri = $this->_buildUri($uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = Hash::merge(array('method' => 'HEAD', 'uri' => $uri), $request);
|
||||||
|
return $this->request($request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Issues a POST request to the specified URI, query, and request.
|
* Issues a POST request to the specified URI, query, and request.
|
||||||
*
|
*
|
||||||
|
@ -524,19 +550,6 @@ class HttpSocket extends CakeSocket {
|
||||||
return $this->request($request);
|
return $this->request($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Issues a HEAD request to the specified URI, query, and request.
|
|
||||||
*
|
|
||||||
* @param string|array $uri URI to request (see {@link _parseUri()})
|
|
||||||
* @param array $data Array of request body data keys and values.
|
|
||||||
* @param array $request An indexed array with indexes such as 'method' or uri
|
|
||||||
* @return mixed Result of request
|
|
||||||
*/
|
|
||||||
public function head($uri = null, $data = array(), $request = array()) {
|
|
||||||
$request = Hash::merge(array('method' => 'HEAD', 'uri' => $uri, 'body' => $data), $request);
|
|
||||||
return $this->request($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalizes URLs into a $uriTemplate. If no template is provided
|
* Normalizes URLs into a $uriTemplate. If no template is provided
|
||||||
* a default one will be used. Will generate the URL using the
|
* a default one will be used. Will generate the URL using the
|
||||||
|
|
0
lib/Cake/Test/Case/Network/CakeSocketTest.php
Executable file → Normal file
0
lib/Cake/Test/Case/Network/CakeSocketTest.php
Executable file → Normal file
50
lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
Executable file → Normal file
50
lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
Executable file → Normal file
|
@ -1049,6 +1049,56 @@ class HttpSocketTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testHead method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testHead() {
|
||||||
|
$this->RequestSocket->reset();
|
||||||
|
$this->RequestSocket->expects($this->at(0))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/'));
|
||||||
|
|
||||||
|
$this->RequestSocket->expects($this->at(1))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=bar'));
|
||||||
|
|
||||||
|
$this->RequestSocket->expects($this->at(2))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=bar'));
|
||||||
|
|
||||||
|
$this->RequestSocket->expects($this->at(3))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=23&foobar=42'));
|
||||||
|
|
||||||
|
$this->RequestSocket->expects($this->at(4))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/', 'version' => '1.0'));
|
||||||
|
|
||||||
|
$this->RequestSocket->expects($this->at(5))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'https://secure.example.com/test.php?one=two'));
|
||||||
|
|
||||||
|
$this->RequestSocket->expects($this->at(6))
|
||||||
|
->method('request')
|
||||||
|
->with(array('method' => 'HEAD', 'uri' => 'https://example.com/oauth/access?clientid=123&redirect_uri=http%3A%2F%2Fexample.com&code=456'));
|
||||||
|
|
||||||
|
$this->RequestSocket->head('http://www.google.com/');
|
||||||
|
$this->RequestSocket->head('http://www.google.com/', array('foo' => 'bar'));
|
||||||
|
$this->RequestSocket->head('http://www.google.com/', 'foo=bar');
|
||||||
|
$this->RequestSocket->head('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23'));
|
||||||
|
$this->RequestSocket->head('http://www.google.com/', null, array('version' => '1.0'));
|
||||||
|
$this->RequestSocket->head('https://secure.example.com/test.php', array('one' => 'two'));
|
||||||
|
$this->RequestSocket->head('https://example.com/oauth/access', array(
|
||||||
|
'clientid' => '123',
|
||||||
|
'redirect_uri' => 'http://example.com',
|
||||||
|
'code' => 456
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test authentication
|
* Test authentication
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue