diff options
author | Christian Schneider | 2006-12-15 17:20:49 +0000 |
---|---|---|
committer | Christian Schneider | 2006-12-15 17:20:49 +0000 |
commit | c61537c05385d8aa13c8f85310c0db26d935e312 (patch) | |
tree | daa9dd941cbed0c290a7fb3052d24e973af766fc | |
parent | fd0ccecb0ce59140422b4dc4d8d9cee2d43dca0b (diff) | |
download | itools-c61537c05385d8aa13c8f85310c0db26d935e312.tar.gz itools-c61537c05385d8aa13c8f85310c0db26d935e312.tar.bz2 itools-c61537c05385d8aa13c8f85310c0db26d935e312.zip |
Send language accept string and consider language for caching
-rw-r--r-- | url.class | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -251,13 +251,31 @@ function get($p=null, $timeout=5000) foreach ($p['data'] as $key => $value) $data_pairs[] = "$key=".urlencode($value); - $p['data'] = implode('&', $data_pairs); + $data = implode('&', $data_pairs); } - $data = !empty($p['data']) ? "\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($p['data']) . "\r\n\r\n" . $p['data'] : ""; + $p['headers'] = (array)$p['headers'] + array( + 'Host' => $url->realhostname, + 'User-Agent' => "Mozilla/4.0 (compatible; MSIE 6.0; ITools)", + 'Accept-Language' => T_lang(), + ); + + if ($datalen = strlen($data)) + { + $method = "POST"; + $p['headers'] += array( + 'Content-Type' => "application/x-www-form-urlencoded", + 'Content-Length' => $datalen, + ); + } + else + $method = "GET"; + + foreach ($p['headers'] as $header => $value) + $headers .= "$header: $value\r\n"; stream_set_timeout($fp, intval($p['timeout']/1000), ($p['timeout']%1000)*1000); - @fputs($fp, (empty($data)?'GET':'POST') . " /$url->path HTTP/1.0\r\nHost: $url->realhostname\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ITools)$data\r\n\r\n"); + @fputs($fp, "$method /$url->path HTTP/1.0\r\n$headers\r\n$data"); while (!feof($fp) && ($line = @fgets($fp, 10240)) && ($line = trim($line))) { @@ -300,8 +318,9 @@ function get_cache_filename($p) if (!is_array($p)) $p = array('url'=>$p); $p += array('cachedir' => $GLOBALS['ULTRAHOME'] . "/var/urlcache"); + $filename = md5(T_lang() . $p['url']); - return $p['cachedir'] . "/" . substr(md5($p['url']), 0, 2) . "/" . md5($p['url']); + return $p['cachedir'] . "/" . substr($filename, 0, 2) . "/$filename"; } |