diff --git a/httprl.module b/httprl.module
old mode 100755
new mode 100644
index b98f1f7..7a86970
--- a/httprl.module
+++ b/httprl.module
@@ -139,7 +139,7 @@ function httprl_build_url_self($path = '', $detect_schema = FALSE) {
  * @return bool
  *   return value from httprl_send_request().
  */
-function httprl_request($url, array $options = array()) {
+function httprl_request($url, $options = array()) {
   global $base_root;
   static $https_flags;
   $result = new stdClass();
@@ -606,28 +606,34 @@ function httprl_parse_data(&$result) {
   $result->headers = array();
 
   // Parse the response headers.
-  $cookie_primary_key = 0;
+  $cookie_primary_counter = 0;
   while ($line = trim(array_shift($response))) {
     list($name, $value) = explode(':', $line, 2);
     $name = strtolower($name);
 
     // Parse cookies before they get added to the header.
     if ($name == 'set-cookie') {
-      $cookie_values = explode(';', $value);
-      $first = TRUE;
-      foreach ($cookie_values as $c_name_value) {
-        $c_name_value = explode('=', trim($c_name_value));
-        if ($first) {
-          $primary_key = trim($c_name_value[0]);
-          $result->cookies[$cookie_primary_key]['name'] = trim($c_name_value[0]);
-          $result->cookies[$cookie_primary_key]['value'] = trim($c_name_value[1]);
-          $first = FALSE;
+      // Extract the key value pairs for this cookie.
+      foreach (explode(';', $value) as $cookie_name_value) {
+        $temp = explode('=', trim($cookie_name_value));
+        $cookie_key = trim($temp[0]);
+        $cookie_value = isset($temp[1]) ? trim($temp[1]) : '';
+        unset($temp);
+        // The cookie name-value pair always comes first (RFC 2109 4.2.2).
+        if (!isset($result->cookies[$cookie_primary_counter])) {
+          $result->cookies[$cookie_primary_counter] = array(
+            'name' => $cookie_key,
+            'value' => $cookie_value,
+          );
         }
+        // Extract the rest of the attribute-value pairs.
         else {
-          $result->cookies[$cookie_primary_key][trim($c_name_value[0])] = trim($c_name_value[1]);
+          $result->cookies[$cookie_primary_counter] += array(
+            $cookie_key => $cookie_value,
+          );
         }
       }
-      $cookie_primary_key++;
+      $cookie_primary_counter++;
     }
 
     // Add key value pairs to the header; including cookies.
