httpclient : Better debug support

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5100 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-03-13 20:38:00 +00:00
parent 6da2d9167f
commit bca528037e

View File

@@ -114,7 +114,7 @@ class Httpclient
*/ */
private $acceptEncoding = "gzip, deflate"; private $acceptEncoding = "gzip, deflate";
// }}} // }}}
/** The constructor /** The constructor
*/ */
@@ -257,7 +257,8 @@ class Httpclient
/** Set / Get the debug mode /** Set / Get the debug mode
* 0: Nothing is displayed, 1: Only URL are displayed, * 0: Nothing is displayed, 1: Only URL are displayed,
* 2: headers only send and received, 3: all the content * 2: headers only send and received, 3: all the content, but without sent
* files, 4: all the content
* @param boolean|null $debug The debug value to set or get * @param boolean|null $debug The debug value to set or get
*/ */
public function debug ($debug = null) public function debug ($debug = null)
@@ -456,7 +457,7 @@ class Httpclient
/** Init the connection to URL /** Init the connection to URL
* Will fill the headersReceived, cookies and port properties. * Will fill the headersReceived, cookies and port properties.
* @param array|null $ssloptions The SSL options (stream_context_set_option) * @param array|null $ssloptions The SSL options (stream_context_set_option)
* @return null * @return $this
*/ */
public function connect ($ssloptions = array ()) public function connect ($ssloptions = array ())
// {{{ // {{{
@@ -606,11 +607,16 @@ class Httpclient
if ($this->method !== "GET" && ! empty ($this->formData)) if ($this->method !== "GET" && ! empty ($this->formData))
{ {
$i = 0; $i = 0;
$this->log (3, "Body Send : \n");
foreach ($this->formData as $key => $val) foreach ($this->formData as $key => $val)
{ {
if ($i > 0) if ($i > 0)
{
$this->tcpclient->send ("&"); $this->tcpclient->send ("&");
$this->log (3, "&");
}
$this->tcpclient->send (rawurlencode ($key)."="); $this->tcpclient->send (rawurlencode ($key)."=");
$this->log (3, rawurlencode ($key)."=");
if (isset ($val{0}) && $val{0} === "@") if (isset ($val{0}) && $val{0} === "@")
{ {
$file = substr ($val, 1); $file = substr ($val, 1);
@@ -619,15 +625,21 @@ class Httpclient
// TODO : Do a loop of 1MB for big files instead of loading the mem // TODO : Do a loop of 1MB for big files instead of loading the mem
$val = file_get_contents ($file); $val = file_get_contents ($file);
$this->tcpclient->send (rawurlencode ($val)); $this->tcpclient->send (rawurlencode ($val));
$this->log (4, rawurlencode ($val));
} }
else else
{
$this->tcpclient->send (rawurlencode ($val)); $this->tcpclient->send (rawurlencode ($val));
$this->log (3, rawurlencode ($val));
}
$i ++; $i ++;
} }
$this->log (3, "\n");
} }
elseif ($this->method !== "GET" && $this->rawData !== "") elseif ($this->method !== "GET" && $this->rawData !== "")
{ {
$this->tcpclient->send ($this->rawData); $this->tcpclient->send ($this->rawData);
$this->log (3, $this->rawData."\n");
} }
// }}} // }}}
@@ -834,9 +846,32 @@ class Httpclient
if ($message) echo "TRUE\n"; else echo "FALSE\n"; if ($message) echo "TRUE\n"; else echo "FALSE\n";
} }
else else
echo "$message\n"; {
echo "$message";
if ($priority < 3)
echo "\n";
}
} }
/** Return the base URL of the site
* @return the URL
*/
public function baseURL ()
// {{{
{
if ($this->url === "")
throw new \Exception ("Can not get baseURL of empty url", 500);
$parseURL = parse_url ($this->url);
$scheme = isset ($parseURL['scheme']) ? $parseURL['scheme'] . '://' : '';
$host = isset ($parseURL['host']) ? $parseURL['host'] : '';
$port = isset ($parseURL['port']) ? ':' . $parseURL['port'] : '';
$user = isset ($parseURL['user']) ? $parseURL['user'] : '';
$pass = isset ($parseURL['pass']) ? ':' . $parseURL['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
return "$scheme$user$pass$host$port";
}
// }}}
////////////////////////////////// //////////////////////////////////
//// COOKIES MANAGEMENT //// //// COOKIES MANAGEMENT ////
////////////////////////////////// //////////////////////////////////