#include <simgear/debug/logstream.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/props/props_io.hxx>
+#include <simgear/structure/exception.hxx>
namespace simgear
{
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]);
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)
{
{
_responseStatus = code;
_responseReason = reason;
- setReadyState(FAILED);
+
+ if( !isComplete() )
+ setReadyState(FAILED);
}
//------------------------------------------------------------------------------
//----------------------------------------------------------------------------
void Request::abort(const std::string& reason)
{
- if( isComplete() )
- return;
-
setFailure(-1, reason);
_willClose = true;
}