#974226 by publicmind: Checking the $result for headers key, before doing any operation in order to prevent the warning thrown.