httpclient : add accept type management

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4805 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-12-26 16:37:43 +00:00
parent 77fc73d022
commit 2e29056132

View File

@@ -4,6 +4,8 @@
* @author Dominique Fournier <dominique@fournier38.fr>
*/
namespace vendor\domframework;
/** This programe allow to get a HTTP page from a site, and examine the content.
* It will store the Cookies, allow to do the redirects, follow links and
* get form / input and send the values.
@@ -93,6 +95,10 @@ class Httpclient
*/
private $referer = "";
/** The accept type of data wanted by the client
*/
private $accept = "text/html;q=0.9, */*;q=0.8";
// }}}
/** The constructor
@@ -170,6 +176,15 @@ class Httpclient
}
// }}}
/** Get the headers sent to the server after the page was get
*/
public function headersSent ()
// {{{
{
return $this->headersSent;
}
// }}}
/** Get the port used for connection
*/
public function port ()
@@ -316,6 +331,19 @@ class Httpclient
}
// }}}
/** Get/Set the accept type of page wanted by the client
* @param string|null $accept The accept types with weight
*/
public function accept ($accept = null)
// {{{
{
if ($accept === null)
return $this->accept;
$this->accept = $accept;
return $this;
}
// }}}
//////////////////////////////////
//// THE ACTIVE METHODS ////
//////////////////////////////////
@@ -447,7 +475,8 @@ class Httpclient
$this->headersSent = array ();
$this->headersSent[] = "$this->method $path HTTP/1.1";
$this->headersSent[] = "Host: ".$parseURL["host"];
$this->headersSent[] = "Accept: text/html;q=0.9, */*;q=0.8";
if ($this->accept != "")
$this->headersSent[] = "Accept: $this->accept";
if ($this->useragent !== "")
$this->headersSent[] = "User-Agent: $this->useragent";
if ($this->referer !== "")
@@ -600,8 +629,8 @@ class Httpclient
if ($this->contentMethod === "chunked")
$this->log (1, "URL $this->method $this->url $this->httpCode Chunked");
else
$this->log (1, "URL $this->method $this->url $this->httpCode ".
$this->bodySize);
$this->log (1, "URL $this->method $this->url $this->httpCode $this->bodySize");
// }}}
}
// }}}