Skip to content

Commit 02dc3b5

Browse files
authored
fix: PostPolicyV4.PostFieldsV4.Builder.addCustomMetadataField() allows to add prefixed an not prefixed custom fields (#398)
* changes to PostPolicyV4 * PostPolicyV4.addCustomMetadataField() allows to add prefixed an not prefixed custom fields * deprecate incorrectly named method * fix format * addCustomMetadataField -> setCustomMetadataField
1 parent 12bd62c commit 02dc3b5

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
* @see <a href="https://cloud.google.com/storage/docs/xml-api/post-object">POST Object</a>
3232
*/
3333
public final class PostPolicyV4 {
34-
private String url;
35-
private Map<String, String> fields;
34+
private final String url;
35+
private final Map<String, String> fields;
3636

3737
private PostPolicyV4(String url, Map<String, String> fields) {
3838
this.url = url;
@@ -58,7 +58,7 @@ public Map<String, String> getFields() {
5858
* Object Form fields</a>
5959
*/
6060
public static final class PostFieldsV4 {
61-
private Map<String, String> fieldsMap;
61+
private final Map<String, String> fieldsMap;
6262

6363
private PostFieldsV4(Builder builder) {
6464
this.fieldsMap = builder.fieldsMap;
@@ -81,10 +81,11 @@ public Map<String, String> getFieldsMap() {
8181
}
8282

8383
public static class Builder {
84-
private Map<String, String> fieldsMap;
84+
private static final String CUSTOM_FIELD_PREFIX = "x-goog-meta-";
85+
private final Map<String, String> fieldsMap;
8586

8687
private Builder() {
87-
fieldsMap = new HashMap<>();
88+
this.fieldsMap = new HashMap<>();
8889
}
8990

9091
public PostFieldsV4 build() {
@@ -121,7 +122,13 @@ public Builder setContentType(String contentType) {
121122
return this;
122123
}
123124

125+
/** @deprecated use {@link #setExpires(String)} */
126+
@Deprecated
124127
public Builder Expires(String expires) {
128+
return setExpires(expires);
129+
}
130+
131+
public Builder setExpires(String expires) {
125132
fieldsMap.put("expires", expires);
126133
return this;
127134
}
@@ -136,8 +143,17 @@ public Builder setSuccessActionStatus(int successActionStatus) {
136143
return this;
137144
}
138145

146+
/** @deprecated use {@link #setCustomMetadataField(String, String)} */
147+
@Deprecated
139148
public Builder AddCustomMetadataField(String field, String value) {
140-
fieldsMap.put("x-goog-meta-" + field, value);
149+
return setCustomMetadataField(field, value);
150+
}
151+
152+
public Builder setCustomMetadataField(String field, String value) {
153+
if (!field.startsWith(CUSTOM_FIELD_PREFIX)) {
154+
field = CUSTOM_FIELD_PREFIX + value;
155+
}
156+
fieldsMap.put(field, value);
141157
return this;
142158
}
143159
}
@@ -270,8 +286,8 @@ Builder addCustomCondition(ConditionV4Type type, String field, String value) {
270286
* Policy document</a>
271287
*/
272288
public static final class PostPolicyV4Document {
273-
private String expiration;
274-
private PostConditionsV4 conditions;
289+
private final String expiration;
290+
private final PostConditionsV4 conditions;
275291

276292
private PostPolicyV4Document(String expiration, PostConditionsV4 conditions) {
277293
this.expiration = expiration;
@@ -363,9 +379,9 @@ public enum ConditionV4Type {
363379
* Policy document</a>
364380
*/
365381
static final class ConditionV4 {
366-
ConditionV4Type type;
367-
String operand1;
368-
String operand2;
382+
final ConditionV4Type type;
383+
final String operand1;
384+
final String operand2;
369385

370386
private ConditionV4(ConditionV4Type type, String operand1, String operand2) {
371387
this.type = type;

0 commit comments

Comments
 (0)