summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass2014-03-06 14:11:25 +0100
committerNathan Gass2014-03-06 14:12:13 +0100
commit311aba6f64ed4b943e391584697b1cdb4d1fb8bf (patch)
treeb7e483ed8fb75cebe2e00c6cac249b7810d794c3
parenta98cd90f1e5889fa586205d12c65209f91361cab (diff)
downloaditools-311aba6f64ed4b943e391584697b1cdb4d1fb8bf.tar.gz
itools-311aba6f64ed4b943e391584697b1cdb4d1fb8bf.tar.bz2
itools-311aba6f64ed4b943e391584697b1cdb4d1fb8bf.zip
keep original header, factor out header parsing code from request, do not send request headers with value null
-rw-r--r--it_url.class26
1 files changed, 20 insertions, 6 deletions
diff --git a/it_url.class b/it_url.class
index ba4ef76..7042598 100644
--- a/it_url.class
+++ b/it_url.class
@@ -268,6 +268,17 @@ function get($p=null, $timeout=5)
return $result;
}
+function parse_http_header($header)
+{
+ foreach (explode("\n", trim($header)) as $line) {
+ $line = trim($line);
+ if (preg_match('#^(HTTP\S+)\s(\d+)#', $line, $parts)) # Parse result code
+ $this->headers[$parts[1]] = $this->result = $parts[2];
+ elseif (preg_match('#^([^:]+): (.*)$#', $line, $parts))
+ $this->headers[$parts[1]] = $parts[2];
+ }
+}
+
function request($p=array())
{
$p += array('totaltimeout' => "999999", 'timeout' => 5);
@@ -313,19 +324,22 @@ function request($p=array())
if ($url->user || $url->pass)
$p['headers'] += array('Authorization' => 'Basic ' . base64_encode($url->user . ':' . $url->pass));
- foreach ($p['headers'] as $header => $value)
+ foreach ($p['headers'] as $header => $value) {
+ if ($value !== null)
$headers .= "$header: $value\r\n";
+ }
stream_set_timeout($fp, intval($p['timeout']), intval(($p['timeout']*1000000)%1000000));
@fputs($fp, "$method /$url->path HTTP/1.0\r\n$headers\r\n$data");
- while (!feof($fp) && ($line = @fgets($fp, 10240)) && ($line = trim($line)) && (time() < $endtime))
+ $url->header = '';
+ while (!feof($fp) && ($origline = @fgets($fp, 10240)) && (trim($origline)) && (time() < $endtime))
{
- if (preg_match('#^(HTTP\S+)\s(\d+)#', $line, $parts)) # Parse result code
- $url->headers[$parts[1]] = $url->result = $parts[2];
- elseif (preg_match('#^([^:]+): (.*)$#', $line, $parts))
- $url->headers[$parts[1]] = $parts[2];
+ $url->header .= $origline;
+ $origline = '';
}
+ $url->header .= $origline;
+ $this->parse_http_header($url->header);
if ($url->result)
{