15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_WELL_KNOWN_HEADERS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_WELL_KNOWN_HEADERS_H
18#include "google/cloud/storage/version.h"
19#include "google/cloud/internal/random.h"
20#include "google/cloud/optional.h"
21#include "absl/types/optional.h"
32GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
35
36
37
38
39
40template <
typename H,
typename T>
41class WellKnownHeader {
43 WellKnownHeader() =
default;
44 explicit WellKnownHeader(T value) : value_(std::move(value)) {}
46 char const* header_name()
const {
return H::header_name(); }
47 bool has_value()
const {
return value_.has_value(); }
48 T
const& value()
const {
return value_.value(); }
50 T value_or(U&& default_val) {
51 return value_.value_or(std::forward<U>(default_val));
55 absl::optional<T> value_;
58template <
typename H,
typename T>
59std::ostream& operator<<(std::ostream& os, WellKnownHeader<H, T>
const& rhs) {
60 if (rhs.has_value()) {
61 return os << rhs.header_name() <<
": " << rhs.value();
63 return os << rhs.header_name() <<
": <not set>";
68
69
70
71
72
74 :
public internal::WellKnownHeader<
ContentType, std::string> {
75 using WellKnownHeader<
ContentType, std::string>::WellKnownHeader;
76 static char const*
header_name() {
return "content-type"; }
80
81
82
83
84
85
87 :
public internal::WellKnownHeader<
CustomHeader, std::string> {
90 explicit CustomHeader(std::string name, std::string value)
91 : WellKnownHeader(std::move(value)), name_(std::move(name)) {}
99std::ostream& operator<<(std::ostream& os,
CustomHeader const& rhs);
102
103
104
105
106
107
108
110 :
public internal::WellKnownHeader<
IfMatchEtag, std::string> {
111 using WellKnownHeader<
IfMatchEtag, std::string>::WellKnownHeader;
112 static char const*
header_name() {
return "If-Match"; }
116
117
118
119
120
121
122
123
127 static char const*
header_name() {
return "If-None-Match"; }
131
132
133
134
135
136
137
145
146
147
148
149
153
154
155
156
157
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
187
188
189
190
194
195
196
197
200 static char const*
prefix() {
return "x-goog-encryption-"; }
203std::ostream& operator<<(std::ostream& os,
EncryptionKey const& rhs);
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
233
234
235
236
240
241
242
243
246 static char const*
prefix() {
return "x-goog-copy-source-encryption-"; }
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268template <
typename Generator>
270 auto constexpr kKeySize = 256 / std::numeric_limits<
unsigned char>::digits;
271 auto constexpr kMinChar = (std::numeric_limits<
char>::min)();
272 auto constexpr kMaxChar = (std::numeric_limits<
char>::max)();
273 std::uniform_int_distribution<
int> uni(kMinChar, kMaxChar);
274 std::string key(
static_cast<std::size_t>(kKeySize),
' ');
275 std::generate_n(key.begin(), key.size(),
276 [&uni, &gen] {
return static_cast<
char>(uni(gen)); });
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
303 using WellKnownHeader<
AcceptEncoding, std::string>::WellKnownHeader;
304 static char const*
header_name() {
return "Accept-Encoding"; }
313GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
AcceptEncoding AcceptEncodingIdentity()
Definition: well_known_headers.h:309
EncryptionKeyData EncryptionDataFromBase64Key(std::string const &key)
Formats an encryption key in base64 format to the data structure required by the Google Cloud Storage...
EncryptionKeyData EncryptionDataFromBinaryKey(std::string const &key)
Formats a (potentially binary) encryption key in the format required by the Google Cloud Storage API.
AcceptEncoding AcceptEncodingGzip()
Definition: well_known_headers.h:307
EncryptionKeyData CreateKeyFromGenerator(Generator &gen)
Creates an encryption key parameter from a pseudo-random number generator.
Definition: well_known_headers.h:269
Modify the accepted encodings.
Definition: well_known_headers.h:302
static char const * header_name()
Definition: well_known_headers.h:304
Set the MIME content type of an object.
Definition: well_known_headers.h:74
static char const * header_name()
Definition: well_known_headers.h:76
A simple wrapper for the encryption key attributes.
Definition: well_known_headers.h:138
std::string algorithm
Definition: well_known_headers.h:139
std::string sha256
Definition: well_known_headers.h:141
std::string key
Definition: well_known_headers.h:140
An optional parameter to set the Customer-Supplied Encryption key.
Definition: well_known_headers.h:183
static char const * prefix()
Definition: well_known_headers.h:200
static EncryptionKey FromBinaryKey(std::string const &key)
Create an encryption key parameter from a binary key.
static EncryptionKey FromBase64Key(std::string const &key)
Creates an encryption key parameter from a key in base64 format.
A pre-condition: apply this operation only if the HTTP Entity Tag matches.
Definition: well_known_headers.h:110
static char const * header_name()
Definition: well_known_headers.h:112
A pre-condition: apply this operation only if the HTTP Entity Tag does not match.
Definition: well_known_headers.h:125
static char const * header_name()
Definition: well_known_headers.h:127
An optional parameter to set the Customer-Supplied Encryption key for rewrite source object.
Definition: well_known_headers.h:228
static SourceEncryptionKey FromBase64Key(std::string const &key)
Creates an encryption key parameter from a key in base64 format.
static char const * prefix()
Definition: well_known_headers.h:246
static SourceEncryptionKey FromBinaryKey(std::string const &key)
Creates a source encryption key parameter from a binary key.