From c3283a53b39fbf5840afd99c6565faaadcefe12e Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Wed, 30 Jun 2010 19:59:09 +0000 Subject: [PATCH] Add header parsing code to the import tool. git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@118 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/unl_migration.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php index e82fa7d7..affb5e79 100644 --- a/sites/all/modules/unl/unl_migration.php +++ b/sites/all/modules/unl/unl_migration.php @@ -449,9 +449,22 @@ class Unl_Migration_Tool curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($this->_curl, CURLOPT_HEADER, TRUE); echo 'Retreiving ' . $url . PHP_EOL; - $content = curl_exec($this->_curl); + $data = curl_exec($this->_curl); $meta = curl_getinfo($this->_curl); - $content = substr($content, $meta['header_size']); + + $rawHeaders = substr($data, 0, $meta['header_size']); + $rawHeaders = trim($rawHeaders); + $rawHeaders = explode("\n", $rawHeaders); + array_shift($rawHeaders); + $headers = array(); + foreach ($rawHeaders as $rawHeader) { + $splitPos = strpos($rawHeader, ':'); + $headerKey = substr($rawHeader, 0, $splitPos); + $headerValue = substr($rawHeader, $splitPos+1); + $headers[$headerKey] = $headerValue; + } + + $content = substr($data, $meta['header_size']); if ($meta['http_code'] == 301) { preg_match('/Location: (.*)/', $content, $matches); -- GitLab