namespace HTTP
{
+class Client;
+
/**
* Base class for HTTP request (and answer).
*/
{
UNSENT = 0,
OPENED,
+ STATUS_RECEIVED,
HEADERS_RECEIVED,
LOADING,
DONE,
void setBodyData( const SGPropertyNode* data );
virtual void setUrl(const std::string& url);
-
+
virtual std::string method() const
{ return _method; }
virtual std::string url() const
{ return _url; }
-
+
+ Client* http() const
+ { return _client; }
+
virtual std::string scheme() const;
virtual std::string path() const;
virtual std::string host() const;
virtual std::string hostAndPort() const;
virtual unsigned short port() const;
virtual std::string query() const;
-
+
StringMap const& responseHeaders() const
{ return _responseHeaders; }
virtual int responseCode() const
{ return _responseStatus; }
-
+
virtual std::string responseReason() const
{ return _responseReason; }
-
+
void setResponseLength(unsigned int l);
virtual unsigned int responseLength() const;
-
+
/**
* Check if request contains body data.
*/
* Retrieve the size of the request body.
*/
virtual size_t bodyLength() const;
-
+
/**
* Retrieve the body data bytes. Will be passed the maximum body bytes
* to return in the buffer, and must return the actual number
- * of bytes written.
+ * of bytes written.
*/
virtual size_t getBodyData(char* s, size_t offset, size_t max_count) const;
-
+
/**
* running total of body bytes received so far. Can be used
* to generate a completion percentage, if the response length is
- * known.
+ * known.
*/
unsigned int responseBytesReceived() const
{ return _receivedBodyBytes; }
-
+
enum HTTPVersion {
HTTP_VERSION_UNKNOWN = 0,
HTTP_0_x, // 0.9 or similar
HTTP_1_0,
HTTP_1_1
};
-
+
HTTPVersion responseVersion() const
{ return _responseVersion; }
-
+
ReadyState readyState() const { return _ready_state; }
- /**
- * Request aborting this request.
- */
- void abort();
+ bool closeAfterComplete() const;
+ bool isComplete() const;
/**
- * Request aborting this request and specify the reported reaseon for it.
+ * Check if the server response indicates pipelining should be continued.
+ * Currently tests that HTTP_1_1 is explicitly supported, and that the
+ * server/proxy did not request Connection: close
*/
- void abort(const std::string& reason);
-
- bool closeAfterComplete() const;
- bool isComplete() const;
+ bool serverSupportsPipelining() const;
protected:
Request(const std::string& url, const std::string method = "GET");
friend class Client;
friend class Connection;
friend class ContentDecoder;
-
+
Request(const Request&); // = delete;
Request& operator=(const Request&); // = delete;
void processBodyBytes(const char* s, int n);
void setReadyState(ReadyState state);
+ void setCloseAfterComplete();
+
+ Client* _client; // HTTP client we're active on
+
std::string _method;
std::string _url;
StringMap _request_headers;
ReadyState _ready_state;
bool _willClose;
+ bool _connectionCloseHeader;
};
typedef SGSharedPtr<Request> Request_ptr;