Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PostPolicyV4.PostFieldsV4.Builder.addCustomMetadataField() allows to add prefixed an not prefixed custom fields #398

Merged
merged 7 commits into from Jul 14, 2020
Expand Up @@ -31,8 +31,8 @@
* @see <a href="https://cloud.google.com/storage/docs/xml-api/post-object">POST Object</a>
*/
public final class PostPolicyV4 {
private String url;
private Map<String, String> fields;
private final String url;
private final Map<String, String> fields;

private PostPolicyV4(String url, Map<String, String> fields) {
this.url = url;
Expand All @@ -58,7 +58,7 @@ public Map<String, String> getFields() {
* Object Form fields</a>
*/
public static final class PostFieldsV4 {
private Map<String, String> fieldsMap;
private final Map<String, String> fieldsMap;

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

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

private Builder() {
fieldsMap = new HashMap<>();
this.fieldsMap = new HashMap<>();
}

public PostFieldsV4 build() {
Expand Down Expand Up @@ -121,7 +122,13 @@ public Builder setContentType(String contentType) {
return this;
}

/** @deprecated use {@link #setExpires(String)} */
@Deprecated
public Builder Expires(String expires) {
return setExpires(expires);
}

public Builder setExpires(String expires) {
fieldsMap.put("expires", expires);
return this;
}
Expand All @@ -136,8 +143,17 @@ public Builder setSuccessActionStatus(int successActionStatus) {
return this;
}

/** @deprecated use {@link #setCustomMetadataField(String, String)} */
@Deprecated
public Builder AddCustomMetadataField(String field, String value) {
fieldsMap.put("x-goog-meta-" + field, value);
return setCustomMetadataField(field, value);
}

public Builder setCustomMetadataField(String field, String value) {
if (!field.startsWith(CUSTOM_FIELD_PREFIX)) {
field = CUSTOM_FIELD_PREFIX + value;
}
fieldsMap.put(field, value);
return this;
}
}
Expand Down Expand Up @@ -270,8 +286,8 @@ Builder addCustomCondition(ConditionV4Type type, String field, String value) {
* Policy document</a>
*/
public static final class PostPolicyV4Document {
private String expiration;
private PostConditionsV4 conditions;
private final String expiration;
private final PostConditionsV4 conditions;

private PostPolicyV4Document(String expiration, PostConditionsV4 conditions) {
this.expiration = expiration;
Expand Down Expand Up @@ -363,9 +379,9 @@ public enum ConditionV4Type {
* Policy document</a>
*/
static final class ConditionV4 {
ConditionV4Type type;
String operand1;
String operand2;
final ConditionV4Type type;
final String operand1;
final String operand2;

private ConditionV4(ConditionV4Type type, String operand1, String operand2) {
this.type = type;
Expand Down