]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/HTTPRequest.cxx
SGPath: fix creating paths with permission checker.
[simgear.git] / simgear / io / HTTPRequest.cxx
index d51d97902ef3d47a61bb9a9f175bb546bd495b73..900b7fc29f9178ea9d2a572752e8af0b2bbe9bc5 100644 (file)
@@ -4,6 +4,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/strutils.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/structure/exception.hxx>
 
 namespace simgear
 {
@@ -115,8 +116,7 @@ void Request::responseStart(const std::string& r)
     const int maxSplit = 2; // HTTP/1.1 nnn reason-string
     string_list parts = strutils::split(r, NULL, maxSplit);
     if (parts.size() != 3) {
-        setFailure(400, "malformed HTTP response header");
-        return;
+        throw sg_io_exception("bad HTTP response");
     }
     
     _responseVersion = decodeHTTPVersion(parts[0]);
@@ -272,6 +272,16 @@ std::string Request::hostAndPort() const
   return u.substr(schemeEnd + 3, hostEnd - (schemeEnd + 3));
 }
 
+//------------------------------------------------------------------------------
+std::string Request::responseMime() const
+{
+  std::string content_type = _responseHeaders.get("content-type");
+  if( content_type.empty() )
+    return "application/octet-stream";
+
+  return content_type.substr(0, content_type.find(';'));
+}
+
 //------------------------------------------------------------------------------
 void Request::setResponseLength(unsigned int l)
 {
@@ -294,7 +304,9 @@ void Request::setFailure(int code, const std::string& reason)
 {
   _responseStatus = code;
   _responseReason = reason;
-  setReadyState(FAILED);
+
+  if( !isComplete() )
+    setReadyState(FAILED);
 }
 
 //------------------------------------------------------------------------------
@@ -336,9 +348,6 @@ void Request::abort()
 //----------------------------------------------------------------------------
 void Request::abort(const std::string& reason)
 {
-  if( isComplete() )
-    return;
-
   setFailure(-1, reason);
   _willClose = true;
 }