diff --git a/httpclient.php b/httpclient.php index 44f258e..8e70ec6 100644 --- a/httpclient.php +++ b/httpclient.php @@ -114,7 +114,7 @@ class Httpclient */ private $acceptEncoding = "gzip, deflate"; - // }}} + // }}} /** The constructor */ @@ -257,7 +257,8 @@ class Httpclient /** Set / Get the debug mode * 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 */ public function debug ($debug = null) @@ -456,7 +457,7 @@ class Httpclient /** Init the connection to URL * Will fill the headersReceived, cookies and port properties. * @param array|null $ssloptions The SSL options (stream_context_set_option) - * @return null + * @return $this */ public function connect ($ssloptions = array ()) // {{{ @@ -606,11 +607,16 @@ class Httpclient if ($this->method !== "GET" && ! empty ($this->formData)) { $i = 0; + $this->log (3, "Body Send : \n"); foreach ($this->formData as $key => $val) { if ($i > 0) + { $this->tcpclient->send ("&"); + $this->log (3, "&"); + } $this->tcpclient->send (rawurlencode ($key)."="); + $this->log (3, rawurlencode ($key)."="); if (isset ($val{0}) && $val{0} === "@") { $file = substr ($val, 1); @@ -619,15 +625,21 @@ class Httpclient // TODO : Do a loop of 1MB for big files instead of loading the mem $val = file_get_contents ($file); $this->tcpclient->send (rawurlencode ($val)); + $this->log (4, rawurlencode ($val)); } else + { $this->tcpclient->send (rawurlencode ($val)); + $this->log (3, rawurlencode ($val)); + } $i ++; } + $this->log (3, "\n"); } elseif ($this->method !== "GET" && $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"; } 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 //// //////////////////////////////////