diff options
author | Chris Wilson <chris+github@qwirx.com> | 2009-01-05 00:48:01 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2009-01-05 00:48:01 +0000 |
commit | 1c5c91f74c636145d02f4bc91b852d669685744e (patch) | |
tree | b1717fe60d21b7916b4bb7f0ae68be91805ab188 /lib/httpserver/HTTPRequest.h | |
parent | ab7be20ac1f1db80aab9201a6cf51640f97ce507 (diff) |
Don't read the whole uploaded body in HTTPRequest::Receive, as the
client may be expecting a 100 Continue header (or other response) before
sending it, and only the HTTPServer should send that for us.
Keep track of the stream that we're reading from, in case there's a body
to read later.
Simplify parsing of HTTP method, and add support for PUT requests.
Add support for parsing Expect headers and storing and retrieving any
unrecognised headers.
Add support for sending a streaming upload from an IOStream with an HTTP
request as the body (e.g. for PUT requests).
Diffstat (limited to 'lib/httpserver/HTTPRequest.h')
-rw-r--r-- | lib/httpserver/HTTPRequest.h | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/httpserver/HTTPRequest.h b/lib/httpserver/HTTPRequest.h index dc81d593..58874092 100644 --- a/lib/httpserver/HTTPRequest.h +++ b/lib/httpserver/HTTPRequest.h @@ -13,6 +13,9 @@ #include <string> #include <map> +#include "CollectInBufferStream.h" + +class HTTPResponse; class IOStream; class IOStreamGetLine; @@ -24,7 +27,7 @@ class IOStreamGetLine; // Created: 26/3/04 // // -------------------------------------------------------------------------- -class HTTPRequest +class HTTPRequest : public CollectInBufferStream { public: enum Method @@ -33,7 +36,8 @@ public: Method_UNKNOWN = 0, Method_GET = 1, Method_HEAD = 2, - Method_POST = 3 + Method_POST = 3, + Method_PUT = 4 }; HTTPRequest(); @@ -56,7 +60,10 @@ public: }; bool Receive(IOStreamGetLine &rGetLine, int Timeout); - bool Send(IOStream &rStream, int Timeout); + bool Send(IOStream &rStream, int Timeout, bool ExpectContinue = false); + void SendWithStream(IOStream &rStreamToSendTo, int Timeout, + IOStream* pStreamToSend, HTTPResponse& rResponse); + void ReadContent(IOStream& rStreamToWriteTo); typedef std::map<std::string, std::string> CookieJar_t; @@ -88,7 +95,20 @@ public: const CookieJar_t *GetCookies() const {return mpCookies;} // WARNING: May return NULL bool GetCookie(const char *CookieName, std::string &rValueOut) const; const std::string &GetCookie(const char *CookieName) const; - + bool GetHeader(const std::string& rName, std::string* pValueOut) const + { + for (std::vector<Header>::const_iterator + i = mExtraHeaders.begin(); + i != mExtraHeaders.end(); i++) + { + if (i->first == rName) + { + *pValueOut = i->second; + return true; + } + } + return false; + } // -------------------------------------------------------------------------- // @@ -109,12 +129,12 @@ public: { mExtraHeaders.push_back(Header(rName, rValue)); } - + bool IsExpectingContinue() const { return mExpectContinue; } + private: void ParseHeaders(IOStreamGetLine &rGetLine, int Timeout); void ParseCookies(const std::string &rHeader, int DataStarts); -private: enum Method mMethod; std::string mRequestURI; std::string mHostName; @@ -127,6 +147,8 @@ private: CookieJar_t *mpCookies; bool mClientKeepAliveRequested; std::vector<Header> mExtraHeaders; + bool mExpectContinue; + IOStream* mpStreamToReadFrom; }; #endif // HTTPREQUEST__H |