+//------------------------------------------------------------------------------
+void Request::setResponseLength(unsigned int l)
+{
+ _responseLength = l;
+}
+
+//------------------------------------------------------------------------------
+unsigned int Request::responseLength() const
+{
+ // if the server didn't supply a content length, use the number
+ // of bytes we actually received (so far)
+ if( (_responseLength == 0) && (_receivedBodyBytes > 0) )
+ return _receivedBodyBytes;
+
+ return _responseLength;
+}
+
+//------------------------------------------------------------------------------
+void Request::setFailure(int code, const std::string& reason)
+{
+ _responseStatus = code;
+ _responseReason = reason;
+
+ if( !isComplete() )
+ setReadyState(FAILED);
+}
+
+//------------------------------------------------------------------------------
+void Request::setReadyState(ReadyState state)
+{
+ _ready_state = state;
+ if( state == DONE )
+ {
+ // Finish C++ part of request to ensure everything is finished (for example
+ // files and streams are closed) before calling any callback (possibly using
+ // such files)
+ onDone();
+ onAlways();
+
+ _cb_done(this);
+ }
+ else if( state == FAILED )
+ {
+ onFail();
+ onAlways();
+
+ _cb_fail(this);
+ }
+ else
+ return;
+
+ _cb_always(this);
+}
+
+//------------------------------------------------------------------------------
+void Request::abort()
+{
+ abort("Request aborted.");
+}
+
+//----------------------------------------------------------------------------
+void Request::abort(const std::string& reason)
+{
+ setFailure(-1, reason);
+ _willClose = true;
+}
+
+//------------------------------------------------------------------------------
+bool Request::closeAfterComplete() const
+{
+ // for non HTTP/1.1 connections, assume server closes
+ return _willClose || (_responseVersion != HTTP_1_1);
+}
+
+//------------------------------------------------------------------------------
+bool Request::isComplete() const
+{
+ return _ready_state == DONE || _ready_state == FAILED;
+}
+
+//------------------------------------------------------------------------------
+bool Request::hasBodyData() const
+{
+ return !_request_media_type.empty();
+}
+
+//------------------------------------------------------------------------------
+std::string Request::bodyType() const
+{
+ return _request_media_type;
+}
+
+//------------------------------------------------------------------------------
+size_t Request::bodyLength() const
+{
+ return _request_data.length();
+}
+
+//------------------------------------------------------------------------------
+size_t Request::getBodyData(char* s, size_t offset, size_t max_count) const
+{
+ size_t bytes_available = _request_data.size() - offset;
+ size_t bytes_to_read = std::min(bytes_available, max_count);
+
+ memcpy(s, _request_data.data() + offset, bytes_to_read);