Skip to content

Commit 763293b

Browse files
authored
feat: add Content-* , Cache-Control and x-goog-user-project header support to CreateMultipartUploadRequest
2 parents 6f4d255 + 2f5450b commit 763293b

File tree

3 files changed

+334
-2
lines changed

3 files changed

+334
-2
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/MultipartUploadHttpRequestManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ private void addHeadersForCreateMultipartUpload(
224224
if (request.getContentType() != null) {
225225
headers.put("Content-Type", request.getContentType());
226226
}
227+
if (request.getContentDisposition() != null) {
228+
headers.put("Content-Disposition", request.getContentDisposition());
229+
}
230+
if (request.getContentEncoding() != null) {
231+
headers.put("Content-Encoding", request.getContentEncoding());
232+
}
233+
if (request.getContentLanguage() != null) {
234+
headers.put("Content-Language", request.getContentLanguage());
235+
}
236+
if (request.getCacheControl() != null) {
237+
headers.put("Cache-Control", request.getCacheControl());
238+
}
227239
if (request.getStorageClass() != null) {
228240
headers.put("x-goog-storage-class", request.getStorageClass().toString());
229241
}
@@ -242,6 +254,9 @@ private void addHeadersForCreateMultipartUpload(
242254
headers.put(
243255
"x-goog-custom-time", Utils.offsetDateTimeRfc3339Codec.encode(request.getCustomTime()));
244256
}
257+
if (request.getUserProject() != null) {
258+
headers.put("x-goog-user-project", request.getUserProject());
259+
}
245260
}
246261

247262
private static String urlEncode(String value) {

google-cloud-storage/src/main/java/com/google/cloud/storage/multipartupload/model/CreateMultipartUploadRequest.java

Lines changed: 152 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,34 @@ public final class CreateMultipartUploadRequest {
3636
private final String key;
3737
private final PredefinedAcl cannedAcl;
3838
private final String contentType;
39+
private final String contentDisposition;
40+
private final String contentEncoding;
41+
private final String contentLanguage;
42+
private final String cacheControl;
3943
private final Map<String, String> metadata;
4044
private final StorageClass storageClass;
4145
private final OffsetDateTime customTime;
4246
private final String kmsKeyName;
4347
private final ObjectLockMode objectLockMode;
4448
private final OffsetDateTime objectLockRetainUntilDate;
49+
private final String userProject;
4550

4651
private CreateMultipartUploadRequest(Builder builder) {
4752
this.bucket = builder.bucket;
4853
this.key = builder.key;
4954
this.cannedAcl = builder.cannedAcl;
5055
this.contentType = builder.contentType;
56+
this.contentDisposition = builder.contentDisposition;
57+
this.contentEncoding = builder.contentEncoding;
58+
this.contentLanguage = builder.contentLanguage;
59+
this.cacheControl = builder.cacheControl;
5160
this.metadata = builder.metadata;
5261
this.storageClass = builder.storageClass;
5362
this.customTime = builder.customTime;
5463
this.kmsKeyName = builder.kmsKeyName;
5564
this.objectLockMode = builder.objectLockMode;
5665
this.objectLockRetainUntilDate = builder.objectLockRetainUntilDate;
66+
this.userProject = builder.userProject;
5767
}
5868

5969
/**
@@ -101,6 +111,51 @@ public String getContentType() {
101111
return contentType;
102112
}
103113

114+
/**
115+
* Returns the presentational information about how the object data is to be transmitted.
116+
*
117+
* @return The Content-Disposition
118+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
119+
*/
120+
@BetaApi
121+
public String getContentDisposition() {
122+
return contentDisposition;
123+
}
124+
125+
/**
126+
* Returns the compression algorithm that was used to compress the data being uploaded.
127+
*
128+
* @return The Content-Encoding
129+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
130+
*/
131+
@BetaApi
132+
public String getContentEncoding() {
133+
return contentEncoding;
134+
}
135+
136+
/**
137+
* Returns the language code of the content.
138+
*
139+
* @return The Content-Language
140+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
141+
*/
142+
@BetaApi
143+
public String getContentLanguage() {
144+
return contentLanguage;
145+
}
146+
147+
/**
148+
* Returns the conditions under which the resulting object should be cached if it is publicly
149+
* accessible.
150+
*
151+
* @return The Cache-Control
152+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
153+
*/
154+
@BetaApi
155+
public String getCacheControl() {
156+
return cacheControl;
157+
}
158+
104159
/**
105160
* Returns the custom metadata of the object.
106161
*
@@ -167,6 +222,16 @@ public OffsetDateTime getObjectLockRetainUntilDate() {
167222
return objectLockRetainUntilDate;
168223
}
169224

225+
/**
226+
* Returns the project to be billed for charges associated with this request.
227+
*
228+
* @return The user project
229+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
230+
*/
231+
public String getUserProject() {
232+
return userProject;
233+
}
234+
170235
@Override
171236
public boolean equals(Object o) {
172237
if (this == o) {
@@ -180,12 +245,17 @@ public boolean equals(Object o) {
180245
&& Objects.equals(key, that.key)
181246
&& cannedAcl == that.cannedAcl
182247
&& Objects.equals(contentType, that.contentType)
248+
&& Objects.equals(contentDisposition, that.contentDisposition)
249+
&& Objects.equals(contentEncoding, that.contentEncoding)
250+
&& Objects.equals(contentLanguage, that.contentLanguage)
251+
&& Objects.equals(cacheControl, that.cacheControl)
183252
&& Objects.equals(metadata, that.metadata)
184253
&& Objects.equals(storageClass, that.storageClass)
185254
&& Objects.equals(customTime, that.customTime)
186255
&& Objects.equals(kmsKeyName, that.kmsKeyName)
187256
&& objectLockMode == that.objectLockMode
188-
&& Objects.equals(objectLockRetainUntilDate, that.objectLockRetainUntilDate);
257+
&& Objects.equals(objectLockRetainUntilDate, that.objectLockRetainUntilDate)
258+
&& Objects.equals(userProject, that.userProject);
189259
}
190260

191261
@Override
@@ -195,12 +265,17 @@ public int hashCode() {
195265
key,
196266
cannedAcl,
197267
contentType,
268+
contentDisposition,
269+
contentEncoding,
270+
contentLanguage,
271+
cacheControl,
198272
metadata,
199273
storageClass,
200274
customTime,
201275
kmsKeyName,
202276
objectLockMode,
203-
objectLockRetainUntilDate);
277+
objectLockRetainUntilDate,
278+
userProject);
204279
}
205280

206281
@Override
@@ -210,12 +285,17 @@ public String toString() {
210285
.add("key", key)
211286
.add("cannedAcl", cannedAcl)
212287
.add("contentType", contentType)
288+
.add("contentDisposition", contentDisposition)
289+
.add("contentEncoding", contentEncoding)
290+
.add("contentLanguage", contentLanguage)
291+
.add("cacheControl", cacheControl)
213292
.add("metadata", metadata)
214293
.add("storageClass", storageClass)
215294
.add("customTime", customTime)
216295
.add("kmsKeyName", kmsKeyName)
217296
.add("objectLockMode", objectLockMode)
218297
.add("objectLockRetainUntilDate", objectLockRetainUntilDate)
298+
.add("userProject", userProject)
219299
.toString();
220300
}
221301

@@ -241,12 +321,17 @@ public static final class Builder {
241321
private String key;
242322
private PredefinedAcl cannedAcl;
243323
private String contentType;
324+
private String contentDisposition;
325+
private String contentEncoding;
326+
private String contentLanguage;
327+
private String cacheControl;
244328
private Map<String, String> metadata;
245329
private StorageClass storageClass;
246330
private OffsetDateTime customTime;
247331
private String kmsKeyName;
248332
private ObjectLockMode objectLockMode;
249333
private OffsetDateTime objectLockRetainUntilDate;
334+
private String userProject;
250335

251336
private Builder() {}
252337

@@ -303,6 +388,58 @@ public Builder contentType(String contentType) {
303388
return this;
304389
}
305390

391+
/**
392+
* Specifies presentational information about the object data.
393+
*
394+
* @param contentDisposition The content disposition for the object.
395+
* @return this builder
396+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
397+
*/
398+
@BetaApi
399+
public Builder contentDisposition(String contentDisposition) {
400+
this.contentDisposition = contentDisposition;
401+
return this;
402+
}
403+
404+
/**
405+
* Specifies the compression algorithm that was used to compress the object data.
406+
*
407+
* @param contentEncoding The content encoding for the object.
408+
* @return this builder
409+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
410+
*/
411+
@BetaApi
412+
public Builder contentEncoding(String contentEncoding) {
413+
this.contentEncoding = contentEncoding;
414+
return this;
415+
}
416+
417+
/**
418+
* Specifies the language of the object's content.
419+
*
420+
* @param contentLanguage The content language for the object.
421+
* @return this builder
422+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
423+
*/
424+
@BetaApi
425+
public Builder contentLanguage(String contentLanguage) {
426+
this.contentLanguage = contentLanguage;
427+
return this;
428+
}
429+
430+
/**
431+
* Specifies the caching behavior for the object when it is publicly accessible.
432+
*
433+
* @param cacheControl The cache control settings for the object.
434+
* @return this builder
435+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
436+
*/
437+
@BetaApi
438+
public Builder cacheControl(String cacheControl) {
439+
this.cacheControl = cacheControl;
440+
return this;
441+
}
442+
306443
/**
307444
* The custom metadata of the object.
308445
*
@@ -385,6 +522,19 @@ public Builder objectLockRetainUntilDate(OffsetDateTime objectLockRetainUntilDat
385522
return this;
386523
}
387524

525+
/**
526+
* Specifies the project to be billed for this request.
527+
*
528+
* @param userProject The project ID to bill for this request.
529+
* @return this builder
530+
* @since 2.61.0 This new api is in preview and is subject to breaking changes.
531+
*/
532+
@BetaApi
533+
public Builder userProject(String userProject) {
534+
this.userProject = userProject;
535+
return this;
536+
}
537+
388538
/**
389539
* Creates a new {@link CreateMultipartUploadRequest} object.
390540
*

0 commit comments

Comments
 (0)