Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Parse/src/main/java/com/parse/ParseHttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package com.parse;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
Expand All @@ -21,7 +22,7 @@
protected ParseHttpRequest(Builder builder) {
this.url = builder.url;
this.method = builder.method;
this.headers = builder.headers;
this.headers = Collections.unmodifiableMap(new HashMap<>(builder.headers));
this.body = builder.body;
}

Expand Down Expand Up @@ -59,8 +60,6 @@ public Builder(ParseHttpRequest request) {
this.url = request.url;
this.method = request.method;
this.headers = new HashMap<>(request.headers);
// TODO(mengyan) This direct copy make ParseHttpRequest not truly immutable.
// We need to 'clone' a ParseHttpBody here.
this.body = request.body;
}

Expand Down
18 changes: 16 additions & 2 deletions Parse/src/main/java/com/parse/ParseHttpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

/* package */ abstract T self();

public Init() {
this.headers = new HashMap<>();
}

public T setStatusCode(int statusCode) {
this.statusCode = statusCode;
return self();
Expand All @@ -50,7 +54,17 @@ public T setReasonPhase(String reasonPhase) {
}

public T setHeaders(Map<String, String> headers) {
this.headers = Collections.unmodifiableMap(new HashMap<>(headers));
this.headers = new HashMap<>(headers);
return self();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to:

public T addHeaders(Map<String, String> headers) {
  this.headers.addAll(headers);
  return self();
}

Leaving it as setHeaders where it can clear all old values seem like it could be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk


public T addHeaders(Map<String, String> headers) {
this.headers.putAll(headers);
return self();
}

public T addHeader(String key, String value) {
this.headers.put(key, value);
return self();
}

Expand Down Expand Up @@ -84,7 +98,7 @@ public ParseHttpResponse build() {
this.content = builder.content;
this.totalSize = builder.totalSize;
this.reasonPhrase = builder.reasonPhrase;
this.headers = builder.headers;
this.headers = Collections.unmodifiableMap(new HashMap<>(builder.headers));
this.contentType = builder.contentType;
}

Expand Down
Loading