From c7326fa0883c1a45b7364426be58fd0a24fe085c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 8 Mar 2011 12:25:38 +0000 Subject: [PATCH] Fix for wrong detection of broken HTTP server --- inc/functions.php | 19 +++++++++++++++++++ inc/http-functions.php | 17 +++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 119c23891d..1c9820ccef 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2289,6 +2289,25 @@ function detectMultiBytePrefix ($str) { return $mbPrefix; } +// Searches the given array for a sub-string match and returns all found keys in an array +function getArrayKeysFromSubStrArray ($heystack, array $needles, $offset = 0) { + // Init array for all found keys + $keys = array(); + + // Now check all entries + foreach ($needles as $key => $needle) { + // Do we have found a partial string? + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'heystack='.$heystack.',key='.$key.',needle='.$needle.',offset='.$offset); + if (strpos($heystack, $needle, $offset) !== false) { + // Add the found key + $keys[] = $key; + } // END - if + } // END - foreach + + // Return the array + return $keys; +} + //----------------------------------------------------------------------------- // Automatically re-created functions, all taken from user comments on www.php.net //----------------------------------------------------------------------------- diff --git a/inc/http-functions.php b/inc/http-functions.php index b0cbca319d..6289d6d2b8 100644 --- a/inc/http-functions.php +++ b/inc/http-functions.php @@ -267,7 +267,7 @@ function sendRawRequest ($host, $request) { // Check for broken HTTP implementations if (substr(strtolower($line), 0, 7) == 'server:') { // Anomic (see http://anomic.de, http://yacy.net) is currently broken - $GLOBALS['is_http_server_broken'] = in_array(trim(substr(strtolower($line), 7)), array('anomichttpd')); + $GLOBALS['is_http_server_broken'] = (count(getArrayKeysFromSubStrArray(strtolower($line), array('anomichttpd'))) > 0); } // END - if // Add it to response @@ -467,7 +467,7 @@ if (!function_exists('http_build_query')) { if (is_array($v) || is_object($v)) { array_push($ret, http_build_query($v, '', $sep, $k)); } else { - array_push($ret, $k.'='.urlencode($v)); + array_push($ret, $k . '=' . urlencode($v)); } } // END - foreach @@ -543,8 +543,9 @@ offset['.__LINE__.']='.$offset.'
'; /* * Hack for e.g. YaCy HTTPDaemon (Anomic Server), this HTTP server - * is currently (revision 7567) broken and does not include the \r\n - * characters when it does sent "chunked" messages. + * is currently (revision 7567 and maybe earlier) broken and does + * not include the \r\n characters when it sents a "chunked" HTTP + * message. */ $count = 0; if (isBrokenHttpServerImplentation()) { @@ -552,7 +553,11 @@ offset['.__LINE__.']='.$offset.'
'; $count = call_user_func_array($mbPrefix . 'substr_count', array($next, getConfig('HTTP_EOL'))); } // END - if - // Correct it because we need to subtract occurrences of \r\n + /* + * Correct chunk length because some broken HTTP server + * implementation subtract occurrences of \r\n in their chunk + * lengths. + */ $chunkLen = hexdec(rtrim($chunkLenHex, getConfig('HTTP_EOL'))) - ($count * strlen(getConfig('HTTP_EOL'))); // Add next chunk to $dechunk @@ -575,7 +580,7 @@ chunk=
'.replaceReturnNewLine(htmlentities($chunk)).'
'); break; } // END - if - // Calculate next offset of chunk + // Calculate offset of next chunk $offset = call_user_func_array($mbPrefix . 'strpos', array($chunk, getConfig('HTTP_EOL'), $offset + $chunkLen)) + 2; /* DEBUG: * -- 2.30.2