]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/HTTPRequest.cxx
Drop explicit SDK setting on Mac
[simgear.git] / simgear / io / HTTPRequest.cxx
index 46c64d5df84654c3698df0f72b59fab81ecd2de0..b9466ebf36d11a3938365f9f035e7830a36add6c 100644 (file)
@@ -1,3 +1,20 @@
+// Copyright (C) 2011  James Turner <zakalawe@mac.com>
+// Copyright (C) 2013  Thomas Geymayer <tomgey@gmail.com>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
+
 #include "HTTPRequest.hxx"
 
 #include <simgear/compiler.h>
@@ -39,7 +56,7 @@ Request* Request::done(const Callback& cb)
   if( _ready_state == DONE )
     cb(this);
   else
-    _cb_done = cb;
+    _cb_done.push_back(cb);
 
   return this;
 }
@@ -50,7 +67,7 @@ Request* Request::fail(const Callback& cb)
   if( _ready_state == FAILED )
     cb(this);
   else
-    _cb_fail = cb;
+    _cb_fail.push_back(cb);
 
   return this;
 }
@@ -61,7 +78,7 @@ Request* Request::always(const Callback& cb)
   if( isComplete() )
     cb(this);
   else
-    _cb_always = cb;
+    _cb_always.push_back(cb);
 
   return this;
 }
@@ -272,6 +289,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 +321,9 @@ void Request::setFailure(int code, const std::string& reason)
 {
   _responseStatus = code;
   _responseReason = reason;
-  setReadyState(FAILED);
+
+  if( !isComplete() )
+    setReadyState(FAILED);
 }
 
 //------------------------------------------------------------------------------
@@ -309,22 +338,19 @@ void Request::setReadyState(ReadyState state)
     onDone();
     onAlways();
 
-    if( _cb_done )
-      _cb_done(this);
+    _cb_done(this);
   }
   else if( state == FAILED )
   {
     onFail();
     onAlways();
 
-    if( _cb_fail )
-      _cb_fail(this);
+    _cb_fail(this);
   }
   else
     return;
 
-  if( _cb_always )
-    _cb_always(this);
+  _cb_always(this);
 }
 
 //------------------------------------------------------------------------------
@@ -336,9 +362,6 @@ void Request::abort()
 //----------------------------------------------------------------------------
 void Request::abort(const std::string& reason)
 {
-  if( isComplete() )
-    return;
-
   setFailure(-1, reason);
   _willClose = true;
 }