Repository navigation
HttpSocket changes
The HttpSocket class has undergone some changes.
Following others places in core, the HttpSocket do not change the headers. The RFC 2616 says that headers are case insensitive.
So, if your server send the below header:
HTTP/1.1 200 OK
Date: Mon, 16 Apr 2007 04:14:16 GMT
server: CakeHttp Server
content-tyPe: text/htmlYou $http->response['header'] will be:
Array(
'Date' => 'Mon, 16 Apr 2007 04:14:16 GMT',
'server' => 'CakeHttp Server',
'content-tyPe' => 'text/html'
)The methods get(), post(), put(), delete() and request() now returns the content as reference. It is good when the server response is big. The reference is to $http->response['body']. To use it, you need receive the result with reference, for example:
$response =& $http->get('http://www.cakephp.org');HttpSocket have a new method called setContentResource(). Setting a resource with this method the content will be wrote to this resource, using fwrite(). To you download a file, you can do:
$http = new HttpSocket();
$f = fopen('baery.xml', 'w');
$http->setContentResource($f);
$http->get('http://bakery.cakephp.org/comments.rss');
fclose($f);Attention: The header is not included in file.
To disable the save in resource, use $http->setContentResource(false).
The cookie is stored by host and not by instance. Then, if you make two request to different server, the cookie will be separated, avoiding possible security problem.
Now you can create your authentication method to use with HttpSocket. To it, create a file `app/libs/http/your_method_autenthication.php' with the content:
<?php
class YourMethodAuthentication {
/**
* Authentication
*
* @param HttpSocket $http
* @param array $authInfo
* @return void
*/
public static function authentication(HttpSocket $http, &$authInfo) {
// Do something, for example set $http->request['header']['Authentication'] value
}
}To set the auth config, you can use the new method setAuthConfig():
$http->setAuthConfig('YourMethod', array('config1' => 'value1', 'config2' => 'value2'));
$http->get('http://secure.your-site.com');The Basic authentication is still supported by core, and now Digest authentication too! To use this methods you can set $http->setAuthConfig('Basic', 'user', 'password');
As the auth configuration, you can to configure the proxy authentication. You can create your customized method to proxy authentication in the same class of authentication. For example:
<?php
class YourMethodAuthentication {
/**
* Authentication
*
* @param HttpSocket $http
* @param array $authInfo
* @return void
*/
public static function authentication(HttpSocket $http, &$authInfo) {
// Do something, for example set $http->request['header']['Authentication'] value
}
/**
* Proxy Authentication
*
* @param HttpSocket $http
* @param array $proxyInfo
* @return void
*/
public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) {
// Do something, for example set $http->request['header']['Proxy-Authentication'] value
}
}To use, you must call the HttpSocket::setProxyConfig() as same the HttpSocket::setAuthConfig().