diff --git a/httprl.module b/httprl.module
index 477eefa..60cf0a0 100755
--- a/httprl.module
+++ b/httprl.module
@@ -606,9 +606,31 @@ function httprl_parse_data(&$result) {
   $result->headers = array();
 
   // Parse the response headers.
+  $cookie_primary_key = 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;
+        }
+        else {
+          $result->cookies[$cookie_primary_key][trim($c_name_value[0])] = trim($c_name_value[1]);
+        }
+      }
+      $cookie_primary_key++;
+    }
+
+    // Add key value pairs to the header; including cookies.
     if (isset($result->headers[$name]) && $name == 'set-cookie') {
       // RFC 2109: the Set-Cookie response header comprises the token Set-
       // Cookie:, followed by a comma-separated list of one or more cookies.
@@ -676,6 +698,7 @@ function httprl_parse_data(&$result) {
     case 302: // Moved temporarily
     case 307: // Moved temporarily
       $location = @parse_url($result->headers['location']);
+
       // If location isn't fully qualified URL (as per W3 RFC2616), build one.
       if (empty($location['scheme']) || empty($location['host'])) {
         // Get the important parts from the original request.
@@ -697,7 +720,7 @@ function httprl_parse_data(&$result) {
       }
       else {
         // Redirect to the new location.
-        // TODO: Parse cookies from header and send them in the redirect request.
+        // TODO: Send cookies in the redirect request if domain/path match.
         $result->options['max_redirects']--;
         $result->options['headers']['Referer'] = $result->url;
         // Remove the host from the header.
