On 24/giu/07, at 00:18:00, Pádraic Brady wrote:
(e.g. if a prior request sets an Accept header it can't be removed
without the subclassed method, and would in its absence play havoc
in web services which use that header to determine what document
type to return).
The fact you're subclassing Zend_Http_Client not to add specific
functionality but just to get it working right looks like a big
warning sign.
I'm not sure I'd class it as a bug. This behaviour is not
unexpected given the documentation, and it should be obvious that
headers are not parameters - so it's a possible improvement rather.
Behaviour may be expected and may not be classed as a bug, yet it's
questionable from a design perspective and definitely not common,
looking at same type of libraries in other languages. I understand
that dealing with such issues is difficult now ZF's reaching GA
status but
discussing it is always worth.
I'm including an example of what it looks to me a more consistent and
usable interface:
---code---
class Zend_Http_Client
{
public function __construct($config = null);
public function setConfig($config);
public function setCookieJar(Zend_Http_CookieJar $cookiejar =
true);
/* not sure about following name, commodity method that can be
omitted */
public function setAuthRules(Zend_Http_AuthRules $authRules =
true);
/* may be useful as well, can be omitted */
public function setDefaultHeaders($headers);
public function getLastRequest();
public function getLastResponse();
public function setAdapter($adapter);
/*
* $request can be:
* - Zend_Http_Request, other params should be unset
* - Zend_Uri_Http or a uri string. other params should be as
for Zend_Http_Request::__construct()
*/
public function request($request, $method = null, $headers =
null, $body = null);
}
class Zend_Http_Request
{
public function __construct($uri, $method = null, $headers =
null, $body = null);
public function setUri($uri);
public function getUri($uri);
public function setMethod($method);
public function getMethod($method);
public function setHeaders($name, $value = null);
public function getHeaders($name = null);
/* setParameterGet() and setParameterPost() names imply
some sort of simmetry which is fake. You can always
setParameterGet()
for GET/POST requests, but you can setParameterPost() for
POSTs only.
I think following names would be better.
*/
public function setQueryParameter($name, $value = null);
public function setBodyParameter($name, $value = null);
public function setAuth($user, $password = '', $type =
self::AUTH_BASIC);
public function setFileUpload($filename, $formname, $data =
null, $ctype = null);
public function setEncType($enctype = self::ENC_URLENCODED);
public function setRawData($data, $enctype = null);
public function asString();
/* NB, no resetParameters() needed, old Zend_Http_Request is
discarded and a new one is used.
* Cleaning is implicit.
* A method to clean the request object or to clone a new clean
request object (better) could be added.
*/
}
class Zend_Http_AuthRules
{
public function addAuthRule($username, $password, $domain,
$path, $type);
public function addAuthRuleFromRequest(Zend_Http_Request
$request, $username = null, $password = null);
}
/* example usage */
$client = new Zend_Http_Client(array('name' => 'MyBot', $maxredirects
=> 3));
/* quick GET */
$response = $client->request('http://www.example.org/');
/* POST with request */
$request = new Zend_Http_Request('http://www.example.org/login',
'POST');
$request->setBodyParameters(array('u' => 'me', 'p' => 'mypass'));
$response = $client->request($request);
--- end code ---
Federico