[Box Backup-commit] COMMIT r2436 - box/trunk/lib/httpserver
boxbackup-dev@boxbackup.org
boxbackup-dev@boxbackup.org
Mon, 5 Jan 2009 00:41:12 +0000 (GMT)
Author: chris
Date: 2009-01-05 00:41:11 +0000 (Mon, 05 Jan 2009)
New Revision: 2436
Modified:
box/trunk/lib/httpserver/HTTPResponse.cpp
box/trunk/lib/httpserver/HTTPResponse.h
Log:
Add support for sending an HTTP/1.0 100 Continue response during
processing of a request by HTTPServer, by keeping a pointer to the
socket object.
Modified: box/trunk/lib/httpserver/HTTPResponse.cpp
===================================================================
--- box/trunk/lib/httpserver/HTTPResponse.cpp 2009-01-04 13:57:32 UTC (rev 2435)
+++ box/trunk/lib/httpserver/HTTPResponse.cpp 2009-01-05 00:41:11 UTC (rev 2436)
@@ -25,6 +25,24 @@
// --------------------------------------------------------------------------
//
// Function
+// Name: HTTPResponse::HTTPResponse(IOStream*)
+// Purpose: Constructor for response to be sent to a stream
+// Created: 04/01/09
+//
+// --------------------------------------------------------------------------
+HTTPResponse::HTTPResponse(IOStream* pStreamToSendTo)
+ : mResponseCode(HTTPResponse::Code_NoContent),
+ mResponseIsDynamicContent(true),
+ mKeepAlive(false),
+ mContentLength(-1),
+ mpStreamToSendTo(pStreamToSendTo)
+{
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Function
// Name: HTTPResponse::HTTPResponse()
// Purpose: Constructor
// Created: 26/3/04
@@ -34,7 +52,8 @@
: mResponseCode(HTTPResponse::Code_NoContent),
mResponseIsDynamicContent(true),
mKeepAlive(false),
- mContentLength(-1)
+ mContentLength(-1),
+ mpStreamToSendTo(NULL)
{
}
@@ -123,12 +142,17 @@
// Created: 26/3/04
//
// --------------------------------------------------------------------------
-void HTTPResponse::Send(IOStream &rStream, bool OmitContent)
+void HTTPResponse::Send(bool OmitContent)
{
- if(mContentType.empty())
+ if (!mpStreamToSendTo)
{
- THROW_EXCEPTION(HTTPException, NoContentTypeSet)
+ THROW_EXCEPTION(HTTPException, NoStreamConfigured);
}
+
+ if (GetSize() != 0 && mContentType.empty())
+ {
+ THROW_EXCEPTION(HTTPException, NoContentTypeSet);
+ }
// Build and send header
{
@@ -171,16 +195,20 @@
// NOTE: header ends with blank line in all cases
// Write to stream
- rStream.Write(header.c_str(), header.size());
+ mpStreamToSendTo->Write(header.c_str(), header.size());
}
// Send content
if(!OmitContent)
{
- rStream.Write(GetBuffer(), GetSize());
+ mpStreamToSendTo->Write(GetBuffer(), GetSize());
}
}
+void HTTPResponse::SendContinue()
+{
+ mpStreamToSendTo->Write("HTTP/1.1 100 Continue\r\n");
+}
// --------------------------------------------------------------------------
//
@@ -339,10 +367,16 @@
// Decode the status code
long status = ::strtol(statusLine.substr(9, 3).c_str(), NULL, 10);
// returns zero in error case, this is OK
- if(status < 0) status = 0;
+ if (status < 0) status = 0;
// Store
mResponseCode = status;
+ // 100 Continue responses have no headers, terminating newline, or body
+ if (status == 100)
+ {
+ return;
+ }
+
ParseHeaders(rGetLine, Timeout);
// push back whatever bytes we have left
Modified: box/trunk/lib/httpserver/HTTPResponse.h
===================================================================
--- box/trunk/lib/httpserver/HTTPResponse.h 2009-01-04 13:57:32 UTC (rev 2435)
+++ box/trunk/lib/httpserver/HTTPResponse.h 2009-01-05 00:41:11 UTC (rev 2436)
@@ -28,6 +28,7 @@
class HTTPResponse : public CollectInBufferStream
{
public:
+ HTTPResponse(IOStream* pStreamToSendTo);
HTTPResponse();
~HTTPResponse();
@@ -46,7 +47,8 @@
void SetAsRedirect(const char *RedirectTo, bool IsLocalURI = true);
void SetAsNotFound(const char *URI);
- void Send(IOStream &rStream, bool OmitContent = false);
+ void Send(bool OmitContent = false);
+ void SendContinue();
void Receive(IOStream& rStream, int Timeout = IOStream::TimeOutInfinite);
// void AddHeader(const char *EntireHeaderLine);
@@ -139,6 +141,7 @@
std::string mContentType;
std::vector<Header> mExtraHeaders;
int mContentLength; // only used when reading response from stream
+ IOStream* mpStreamToSendTo; // nonzero only when constructed with a stream
static std::string msDefaultURIPrefix;