]> git.mxchange.org Git - mailer.git/commitdiff
Fix for wrong detection of broken HTTP server
authorRoland Häder <roland@mxchange.org>
Tue, 8 Mar 2011 12:25:38 +0000 (12:25 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 8 Mar 2011 12:25:38 +0000 (12:25 +0000)
inc/functions.php
inc/http-functions.php

index 119c23891de8d87676deec8a70a5d493a2f3a2ee..1c9820ccefa1bf57fe3b31984f4db6a2d83e5504 100644 (file)
@@ -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
 //-----------------------------------------------------------------------------
index b0cbca319d79501193253058fab94b37f113ff3e..6289d6d2b81170fdbe89c71d5f5d8d9f7436956f 100644 (file)
@@ -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[<em>'.__LINE__.'</em>]='.$offset.'<br />';
 
                        /*
                         * 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[<em>'.__LINE__.'</em>]='.$offset.'<br />';
                                $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=<pre>'.replaceReturnNewLine(htmlentities($chunk)).'</pre>');
                                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: *