diff options
-rw-r--r-- | it_url.class | 26 |
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) { |