httpclient : Debug : Add logging of the transaction on screen
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4797 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -14,7 +14,8 @@ class Httpclient
|
|||||||
//// PROPERTIES ////
|
//// PROPERTIES ////
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// {{{
|
// {{{
|
||||||
/** The chunk size staying to read
|
/** The debug depth. 0: Nothing is displayed, 1: Only URL are displayed,
|
||||||
|
* 2: headers only, 3: all the content
|
||||||
*/
|
*/
|
||||||
private $debug = null;
|
private $debug = null;
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ class Httpclient
|
|||||||
{
|
{
|
||||||
if ($debug === null)
|
if ($debug === null)
|
||||||
return $this->debug;
|
return $this->debug;
|
||||||
$this->debug = !! ($debug);
|
$this->debug = intval ($debug);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@@ -319,6 +320,7 @@ class Httpclient
|
|||||||
$location = $parseURLInit["host"].$location;
|
$location = $parseURLInit["host"].$location;
|
||||||
if (! key_exists ("scheme", $parseURLLocation))
|
if (! key_exists ("scheme", $parseURLLocation))
|
||||||
$location = $parseURLInit["scheme"]."://".$location;
|
$location = $parseURLInit["scheme"]."://".$location;
|
||||||
|
$this->log (1, "REDIRECT $this->httpCode to $location");
|
||||||
$content = $this->getPage ($location, $ssloptions);
|
$content = $this->getPage ($location, $ssloptions);
|
||||||
}
|
}
|
||||||
$this->redirectCount = 0;
|
$this->redirectCount = 0;
|
||||||
@@ -394,6 +396,7 @@ class Httpclient
|
|||||||
throw new \Exception ("No host provided to URL", 406);
|
throw new \Exception ("No host provided to URL", 406);
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
|
$this->log (1, "URL $this->method $this->url");
|
||||||
// Prepare the headers to be sent
|
// Prepare the headers to be sent
|
||||||
// {{{
|
// {{{
|
||||||
$this->headersSent = array ();
|
$this->headersSent = array ();
|
||||||
@@ -428,6 +431,8 @@ class Httpclient
|
|||||||
}
|
}
|
||||||
$this->headersSent[] = "Content-Length: $len";
|
$this->headersSent[] = "Content-Length: $len";
|
||||||
}
|
}
|
||||||
|
$this->log (2, "Headers Send :");
|
||||||
|
$this->log (2, $this->headersSent);
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
// Send the request to the server
|
// Send the request to the server
|
||||||
@@ -517,6 +522,8 @@ class Httpclient
|
|||||||
$this->cookieAdd ($parseURL["host"], $cookie);
|
$this->cookieAdd ($parseURL["host"], $cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->log (2, "Headers Received :");
|
||||||
|
$this->log (2, $this->headersReceived);
|
||||||
|
|
||||||
$this->contentMethod = false;
|
$this->contentMethod = false;
|
||||||
if (key_exists ("Transfer-Encoding", $headers) &&
|
if (key_exists ("Transfer-Encoding", $headers) &&
|
||||||
@@ -577,6 +584,7 @@ class Httpclient
|
|||||||
$this->tcpclient->readMode ("text");
|
$this->tcpclient->readMode ("text");
|
||||||
$cr = trim ($this->tcpclient->read ());
|
$cr = trim ($this->tcpclient->read ());
|
||||||
}
|
}
|
||||||
|
$this->log (3, $content);
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@@ -590,6 +598,25 @@ class Httpclient
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
|
/** Display the log message
|
||||||
|
* @param integer $priority The minimal priority to display the message
|
||||||
|
* @param mixed $message The message to display
|
||||||
|
*/
|
||||||
|
public function log ($priority, $message)
|
||||||
|
{
|
||||||
|
if ($this->debug < $priority)
|
||||||
|
return;
|
||||||
|
echo "LOG $this->debug < $priority\n";
|
||||||
|
if (is_array ($message))
|
||||||
|
print_r ($message);
|
||||||
|
elseif (is_bool ($message))
|
||||||
|
{
|
||||||
|
if ($message) echo "TRUE\n"; else echo "FALSE\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
echo "$message\n";
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
//// COOKIES MANAGEMENT ////
|
//// COOKIES MANAGEMENT ////
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user