+//------------------------------------------------------------------------------
+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)
+{
+ SG_LOG(SG_IO, SG_WARN, "HTTP request: set failure:" << code << " reason " << 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);
+}
+
+//------------------------------------------------------------------------------
+bool Request::closeAfterComplete() const
+{
+ // for non HTTP/1.1 connections, assume server closes
+ return _willClose || (_responseVersion != HTTP_1_1);
+}
+
+//------------------------------------------------------------------------------
+
+void Request::setCloseAfterComplete()
+{
+ _willClose = true;
+}