diff --git a/remote_stream_wrapper.inc b/remote_stream_wrapper.inc
index 492272b..77cb389 100644
--- a/remote_stream_wrapper.inc
+++ b/remote_stream_wrapper.inc
@@ -30,9 +30,9 @@ class DrupalRemoteStreamWrapper implements DrupalStreamWrapperInterface {
   /**
    * The content of the file.
    *
-   * @var String
+   * @var string|false
    */
-  protected $stream_content = NULL;
+  protected $stream_content;
 
 
   /**
@@ -138,7 +138,7 @@ class DrupalRemoteStreamWrapper implements DrupalStreamWrapperInterface {
     }
 
     // Attempt to fetch the URL's data using drupal_http_request().
-    if (!$this->getStreamContent()) {
+    if ($this->getStreamContent() === FALSE) {
       return FALSE;
     }
 
@@ -269,21 +269,7 @@ class DrupalRemoteStreamWrapper implements DrupalStreamWrapperInterface {
    * @see http://php.net/manual/en/streamwrapper.stream-stat.php
    */
   public function stream_stat() {
-    $stat = array();
-    $request = drupal_http_request($this->uri, array('method' => 'HEAD'));
-    if (empty($request->error)) {
-      if (isset($request->headers['content-length'])) {
-        $stat['size'] = $request->headers['content-length'];
-      }
-      elseif ($size = strlen($this->getStreamContent())) {
-        // If the HEAD request does not return a Content-Length header, fall
-        // back to performing a full request of the file to determine its file
-        // size.
-        $stat['size'] = $size;
-      }
-    }
-
-    return !empty($stat) ? $this->getStat($stat) : FALSE;
+    return $this->getStat(array('size' => strlen($this->stream_content)));
   }
 
   /**
@@ -382,14 +368,41 @@ class DrupalRemoteStreamWrapper implements DrupalStreamWrapperInterface {
   public function url_stat($uri, $flags) {
     $this->uri = $uri;
     if ($flags & STREAM_URL_STAT_QUIET) {
-      return @$this->stream_stat();
+      return @$this->doUrlStat();
     }
     else {
-      return $this->stream_stat();
+      return $this->doUrlStat();
     }
   }
 
   /**
+   * Performs a HEAD request to get the size of the content.
+   *
+   * This will fallback to a GET request if the HEAD fails.
+   *
+   * @return array|false
+   *   A stat array, or false on failure.
+   */
+  protected function doUrlStat() {
+    $stat = array();
+    $request = drupal_http_request($this->uri, array('method' => 'HEAD'));
+
+    if (empty($request->error) && isset($request->headers['content-length'])) {
+      $stat['size'] = (int) trim($request->headers['content-length']);
+    }
+
+    // If the response is 405, "Method not allowed", or the response didn't
+    // include the content length, do a GET request.
+    elseif ($request->code == 405 || empty($request->error)) {
+      if (($content = $this->getStreamContent()) !== FALSE) {
+        $stat['size'] = strlen($content);
+      }
+    }
+
+    return !empty($stat) ? $this->getStat($stat) : FALSE;
+  }
+
+  /**
    * Support for opendir().
    *
    * @param $uri
@@ -534,10 +547,10 @@ class DrupalRemoteStreamWrapper implements DrupalStreamWrapperInterface {
    */
   protected function getStreamContent() {
     if (!isset($this->stream_content)) {
-      $this->stream_content = NULL;
+      $this->stream_content = FALSE;
 
       $request = drupal_http_request($this->uri);
-      if (empty($request->error) && !empty($request->data)) {
+      if (empty($request->error)) {
         $this->stream_content = $request->data;
       }
     }
