Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 127 lines 8.8 kB view raw
1From 7d58e303159b2fb343af9a1ec4512238efa147c7 Mon Sep 17 00:00:00 2001 2From: Eelco Dolstra <edolstra@gmail.com> 3Date: Mon, 6 Aug 2018 17:15:04 +0200 4Subject: [PATCH] TransferManager: Allow setting a content-encoding for S3 uploads 5 6--- a/aws-cpp-sdk-transfer/include/aws/transfer/TransferHandle.h 7+++ b/aws-cpp-sdk-transfer/include/aws/transfer/TransferHandle.h 8@@ -297,6 +297,14 @@ namespace Aws 9 * Content type of the object being transferred 10 */ 11 inline void SetContentType(const Aws::String& value) { std::lock_guard<std::mutex> locker(m_getterSetterLock); m_contentType = value; } 12+ /** 13+ * Content encoding of the object being transferred 14+ */ 15+ inline const Aws::String GetContentEncoding() const { std::lock_guard<std::mutex> locker(m_getterSetterLock); return m_contentEncoding; } 16+ /** 17+ * Content type of the object being transferred 18+ */ 19+ inline void SetContentEncoding(const Aws::String& value) { std::lock_guard<std::mutex> locker(m_getterSetterLock); m_contentEncoding = value; } 20 /** 21 * In case of an upload, this is the metadata that was placed on the object when it was uploaded. 22 * In the case of a download, this is the object metadata from the GetObject operation. 23@@ -383,6 +391,7 @@ namespace Aws 24 Aws::String m_key; 25 Aws::String m_fileName; 26 Aws::String m_contentType; 27+ Aws::String m_contentEncoding; 28 Aws::String m_versionId; 29 Aws::Map<Aws::String, Aws::String> m_metadata; 30 TransferStatus m_status; 31--- a/aws-cpp-sdk-transfer/include/aws/transfer/TransferManager.h 32+++ b/aws-cpp-sdk-transfer/include/aws/transfer/TransferManager.h 33@@ -154,7 +154,8 @@ namespace Aws 34 const Aws::String& keyName, 35 const Aws::String& contentType, 36 const Aws::Map<Aws::String, Aws::String>& metadata, 37- const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr); 38+ const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr, 39+ const Aws::String& contentEncoding = ""); 40 41 /** 42 * Downloads the contents of bucketName/keyName in S3 to the file specified by writeToFile. This will perform a GetObject operation. 43@@ -246,7 +247,8 @@ namespace Aws 44 const Aws::Map<Aws::String, 45 Aws::String>& metadata, 46 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context, 47- const Aws::String& fileName = ""); 48+ const Aws::String& fileName = "", 49+ const Aws::String& contentEncoding = ""); 50 51 /** 52 * Submits the actual task to task schecduler 53@@ -262,7 +264,8 @@ namespace Aws 54 const Aws::String& keyName, 55 const Aws::String& contentType, 56 const Aws::Map<Aws::String, Aws::String>& metadata, 57- const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context); 58+ const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context, 59+ const Aws::String& contentEncoding); 60 61 /** 62 * Uploads the contents of file, to bucketName/keyName in S3. contentType and metadata will be added to the object. If the object is larger than the configured bufferSize, 63--- a/aws-cpp-sdk-transfer/source/transfer/TransferManager.cpp 64+++ b/aws-cpp-sdk-transfer/source/transfer/TransferManager.cpp 65@@ -87,9 +87,10 @@ namespace Aws 66 const Aws::String& bucketName, 67 const Aws::String& keyName, const Aws::String& contentType, 68 const Aws::Map<Aws::String, Aws::String>& metadata, 69- const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) 70+ const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context, 71+ const Aws::String& contentEncoding) 72 { 73- return this->DoUploadFile(fileStream, bucketName, keyName, contentType, metadata, context); 74+ return this->DoUploadFile(fileStream, bucketName, keyName, contentType, metadata, context, contentEncoding); 75 } 76 77 std::shared_ptr<TransferHandle> TransferManager::DownloadFile(const Aws::String& bucketName, 78@@ -286,6 +287,9 @@ namespace Aws 79 createMultipartRequest.WithKey(handle->GetKey()); 80 createMultipartRequest.WithMetadata(handle->GetMetadata()); 81 82+ if (handle->GetContentEncoding() != "") 83+ createMultipartRequest.WithContentEncoding(handle->GetContentEncoding()); 84+ 85 auto createMultipartResponse = m_transferConfig.s3Client->CreateMultipartUpload(createMultipartRequest); 86 if (createMultipartResponse.IsSuccess()) 87 { 88@@ -441,6 +445,9 @@ namespace Aws 89 90 putObjectRequest.SetContentType(handle->GetContentType()); 91 92+ if (handle->GetContentEncoding() != "") 93+ putObjectRequest.SetContentEncoding(handle->GetContentEncoding()); 94+ 95 auto buffer = m_bufferManager.Acquire(); 96 97 auto lengthToWrite = (std::min)(m_transferConfig.bufferSize, handle->GetBytesTotalSize()); 98@@ -1140,12 +1147,15 @@ namespace Aws 99 const Aws::String& contentType, 100 const Aws::Map<Aws::String, Aws::String>& metadata, 101 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context, 102- const Aws::String& fileName) 103+ const Aws::String& fileName, 104+ const Aws::String& contentEncoding) 105 { 106 auto handle = Aws::MakeShared<TransferHandle>(CLASS_TAG, bucketName, keyName, 0, fileName); 107 handle->SetContentType(contentType); 108 handle->SetMetadata(metadata); 109 handle->SetContext(context); 110+ if (contentEncoding != "") 111+ handle->SetContentEncoding(contentEncoding); 112 113 if (!fileStream->good()) 114 { 115@@ -1213,9 +1223,10 @@ namespace Aws 116 const Aws::String& keyName, 117 const Aws::String& contentType, 118 const Aws::Map<Aws::String, Aws::String>& metadata, 119- const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) 120+ const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context, 121+ const Aws::String& contentEncoding) 122 { 123- auto handle = CreateUploadFileHandle(fileStream.get(), bucketName, keyName, contentType, metadata, context); 124+ auto handle = CreateUploadFileHandle(fileStream.get(), bucketName, keyName, contentType, metadata, context, "", contentEncoding); 125 return SubmitUpload(handle, fileStream); 126 } 127