xp-framework/xp-framework — pull request #140 by mihaighigea (2012-03-27 10:44:41+00:00)
Title: Add peer.URL::getCanonicalURL() + test

Hi,

I think it's better to add a new method in URL class which return the standard compliance URL. The actual returned string by peer.URL::getURL() method (in case of a secured connection) doesn't have signification for any PHP function (SoapClient, Curl, fsockopen etc).

For example, we need to open a secure connection on this address: https+v3://mydomain. If the CurlTransport is used, the following statement will return an error because curl cannot understand "https+v3" scheme:

curl_setopt($curl, CURLOPT_URL, $request->url->getUrl());

The peer.URL::getCanonicalURL() method will trim the arguments like SSL version from returned URL.
The alternate way is to build manually the URL where is used.

These asserts illustrate how it works this change:

// Using existing peer.URL::getURL() method
$this->assertEquals('https+v3://localhost', create(new URL('https+v3://localhost'))->getUrl());

// Using the new peer.URL::getCanonicalURL() method
$this->assertEquals('https://localhost', create(new URL('https+v3://localhost'))->getCanonicalUrl());

What do you say?

Cheers,
Mihai