diff options
author | Chris Wilson <chris+github@qwirx.com> | 2015-08-15 10:58:10 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2015-08-15 10:58:10 +0000 |
commit | 03c4946547d39d4d3c4f32878c47bbd701c6f690 (patch) | |
tree | 43180ec516f6afc81c215bb2cb120e254b0cc1e5 /lib/httpserver | |
parent | feade829d345bd6e34f39dfc32498696e6f588a1 (diff) |
Add configurable timeouts and HEAD request support to S3 client.
Allow getting the Content-Length of an HTTPResponse object.
Diffstat (limited to 'lib/httpserver')
-rw-r--r-- | lib/httpserver/HTTPResponse.h | 3 | ||||
-rw-r--r-- | lib/httpserver/S3Client.cpp | 34 | ||||
-rw-r--r-- | lib/httpserver/S3Client.h | 6 |
3 files changed, 32 insertions, 11 deletions
diff --git a/lib/httpserver/HTTPResponse.h b/lib/httpserver/HTTPResponse.h index 978fa91e..7911f8b5 100644 --- a/lib/httpserver/HTTPResponse.h +++ b/lib/httpserver/HTTPResponse.h @@ -66,6 +66,7 @@ public: int GetResponseCode() const { return mResponseCode; } void SetContentType(const char *ContentType); const std::string& GetContentType() { return mContentType; } + int64_t GetContentLength() { return mContentLength; } void SetAsRedirect(const char *RedirectTo, bool IsLocalURI = true); void SetAsNotFound(const char *URI); @@ -164,7 +165,7 @@ private: bool mKeepAlive; std::string mContentType; std::vector<Header> mExtraHeaders; - int mContentLength; // only used when reading response from stream + int64_t mContentLength; // only used when reading response from stream IOStream* mpStreamToSendTo; // nonzero only when constructed with a stream static std::string msDefaultURIPrefix; diff --git a/lib/httpserver/S3Client.cpp b/lib/httpserver/S3Client.cpp index c9202d36..78b735ad 100644 --- a/lib/httpserver/S3Client.cpp +++ b/lib/httpserver/S3Client.cpp @@ -34,7 +34,7 @@ // Name: S3Client::GetObject(const std::string& rObjectURI) // Purpose: Retrieve the object with the specified URI (key) // from your S3 bucket. -// Created: 09/01/09 +// Created: 09/01/2009 // // -------------------------------------------------------------------------- @@ -46,12 +46,29 @@ HTTPResponse S3Client::GetObject(const std::string& rObjectURI) // -------------------------------------------------------------------------- // // Function +// Name: S3Client::HeadObject(const std::string& rObjectURI) +// Purpose: Retrieve the metadata for the object with the +// specified URI (key) from your S3 bucket. +// Created: 03/08/2015 +// +// -------------------------------------------------------------------------- + +HTTPResponse S3Client::HeadObject(const std::string& rObjectURI) +{ + return FinishAndSendRequest(HTTPRequest::Method_HEAD, rObjectURI); +} + + +HTTPResponse HeadObject(const std::string& rObjectURI); +// -------------------------------------------------------------------------- +// +// Function // Name: S3Client::PutObject(const std::string& rObjectURI, // IOStream& rStreamToSend, const char* pContentType) // Purpose: Upload the stream to S3, creating or overwriting the // object with the specified URI (key) in your S3 // bucket. -// Created: 09/01/09 +// Created: 09/01/2009 // // -------------------------------------------------------------------------- @@ -77,7 +94,7 @@ HTTPResponse S3Client::PutObject(const std::string& rObjectURI, // connection to the server if necessary, which may // throw a ConnectionException. Returns the HTTP // response returned by S3, which may be a 500 error. -// Created: 09/01/09 +// Created: 09/01/2009 // // -------------------------------------------------------------------------- @@ -218,7 +235,7 @@ HTTPResponse S3Client::FinishAndSendRequest(HTTPRequest::Method Method, // necessary, which may throw a ConnectionException. // Returns the HTTP response returned by S3, which may // be a 500 error. -// Created: 09/01/09 +// Created: 09/01/2009 // // -------------------------------------------------------------------------- @@ -229,14 +246,13 @@ HTTPResponse S3Client::SendRequest(HTTPRequest& rRequest, if (pStreamToSend) { - rRequest.SendWithStream(*mapClientSocket, - 30000 /* milliseconds */, + rRequest.SendWithStream(*mapClientSocket, mNetworkTimeout, pStreamToSend, response); } else { - rRequest.Send(*mapClientSocket, 30000 /* milliseconds */); - response.Receive(*mapClientSocket, 30000 /* milliseconds */); + rRequest.Send(*mapClientSocket, mNetworkTimeout); + response.Receive(*mapClientSocket, mNetworkTimeout); } if(!response.IsKeepAlive()) @@ -255,7 +271,7 @@ HTTPResponse S3Client::SendRequest(HTTPRequest& rRequest, // Purpose: Check the status code of an Amazon S3 response, and // throw an exception with a useful message (including // the supplied message) if it's not a 200 OK response. -// Created: 26/07/15 +// Created: 26/07/2015 // // -------------------------------------------------------------------------- diff --git a/lib/httpserver/S3Client.h b/lib/httpserver/S3Client.h index 2d3f71cf..3681213b 100644 --- a/lib/httpserver/S3Client.h +++ b/lib/httpserver/S3Client.h @@ -36,7 +36,8 @@ class S3Client : mpSimulator(pSimulator), mHostName(rHostName), mAccessKey(rAccessKey), - mSecretKey(rSecretKey) + mSecretKey(rSecretKey), + mNetworkTimeout(30000) { } S3Client(std::string HostName, int Port, const std::string& rAccessKey, @@ -49,9 +50,11 @@ class S3Client { } HTTPResponse GetObject(const std::string& rObjectURI); + HTTPResponse HeadObject(const std::string& rObjectURI); HTTPResponse PutObject(const std::string& rObjectURI, IOStream& rStreamToSend, const char* pContentType = NULL); void CheckResponse(const HTTPResponse& response, const std::string& message) const; + int GetNetworkTimeout() const { return mNetworkTimeout; } private: HTTPServer* mpSimulator; @@ -59,6 +62,7 @@ class S3Client int mPort; std::auto_ptr<SocketStream> mapClientSocket; std::string mAccessKey, mSecretKey; + int mNetworkTimeout; // milliseconds HTTPResponse FinishAndSendRequest(HTTPRequest::Method Method, const std::string& rRequestURI, |