diff --git a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike
index cdf766093e26bbbd0bea832b309cf1daf71cf06a..473730b377e205de365c4f9e4a81c643fd974db4 100644
--- a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike
+++ b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike
@@ -558,11 +558,13 @@ int downloaded_bytes()
 
 int total_bytes()
 {
-   int len=(int)headers["content-length"];
-   if(zero_type(len))
-     return -1;
-   else
-     return len;
+  if(!headers)
+    return -1;
+  int len=(int)headers["content-length"];
+  if(zero_type(len))
+    return -1;
+  else
+    return len;
 }
 
 array|mapping|string cast(string to)