Skip to content

Commit 0ec50cf

Browse files
committed
Update for OkHttp3
1 parent 7725a96 commit 0ec50cf

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

Parse/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ android {
4242
dependencies {
4343
compile 'com.parse.bolts:bolts-tasks:1.4.0'
4444

45-
provided 'com.squareup.okhttp3:okhttp:3.2.0'
45+
provided 'com.squareup.okhttp3:okhttp:3.3.0'
4646
provided 'com.facebook.stetho:stetho:1.3.0'
4747

4848
testCompile 'org.robolectric:robolectric:3.0'
4949
testCompile 'org.skyscreamer:jsonassert:1.2.3'
5050
testCompile 'org.mockito:mockito-core:1.10.19'
51-
testCompile 'com.squareup.okhttp3:mockwebserver:3.2.0'
51+
testCompile 'com.squareup.okhttp3:mockwebserver:3.3.0'
5252
}
5353

5454
android.libraryVariants.all { variant ->

Parse/src/main/java/com/parse/http/ParseHttpRequest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.Collections;
1212
import java.util.HashMap;
13+
import java.util.Locale;
1314
import java.util.Map;
1415

1516
/**
@@ -107,8 +108,8 @@ public Builder() {
107108
public Builder(ParseHttpRequest request) {
108109
this.url = request.url;
109110
this.method = request.method;
110-
this.headers = new HashMap<>(request.headers);
111111
this.body = request.body;
112+
setHeaders(request.headers);
112113
}
113114

114115
/**
@@ -157,7 +158,7 @@ public Builder setBody(ParseHttpBody body) {
157158
* @return This {@code Builder}.
158159
*/
159160
public Builder addHeader(String name, String value) {
160-
headers.put(name, value);
161+
headers.put(name.toLowerCase(Locale.US), value);
161162
return this;
162163
}
163164

@@ -181,7 +182,12 @@ public Builder addHeaders(Map<String, String> headers) {
181182
* @return This {@code Builder}.
182183
*/
183184
public Builder setHeaders(Map<String, String> headers) {
184-
this.headers = new HashMap<>(headers);
185+
this.headers = new HashMap<>();
186+
187+
for (Map.Entry<String, String> entry: headers.entrySet()) {
188+
addHeader(entry.getKey(), entry.getValue());
189+
}
190+
185191
return this;
186192
}
187193

@@ -203,7 +209,8 @@ public ParseHttpRequest build() {
203209
private ParseHttpRequest(Builder builder) {
204210
this.url = builder.url;
205211
this.method = builder.method;
206-
this.headers = Collections.unmodifiableMap(new HashMap<>(builder.headers));
212+
builder.setHeaders(builder.headers);
213+
this.headers = Collections.unmodifiableMap(builder.headers);
207214
this.body = builder.body;
208215
}
209216

Parse/src/test/java/com/parse/ParseOkHttpClientTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
import com.parse.http.ParseHttpRequest;
1212
import com.parse.http.ParseHttpResponse;
1313
import com.parse.http.ParseNetworkInterceptor;
14-
import okhttp3.MediaType;
15-
import okhttp3.Protocol;
16-
import okhttp3.Request;
17-
import okhttp3.RequestBody;
18-
import okhttp3.Response;
19-
import okhttp3.ResponseBody;
20-
import okhttp3.mockwebserver.MockResponse;
21-
import okhttp3.mockwebserver.MockWebServer;
22-
import okhttp3.mockwebserver.RecordedRequest;
2314

2415
import org.json.JSONException;
2516
import org.json.JSONObject;
@@ -37,6 +28,15 @@
3728
import java.util.concurrent.TimeUnit;
3829
import java.util.zip.GZIPOutputStream;
3930

31+
import okhttp3.MediaType;
32+
import okhttp3.Protocol;
33+
import okhttp3.Request;
34+
import okhttp3.RequestBody;
35+
import okhttp3.Response;
36+
import okhttp3.ResponseBody;
37+
import okhttp3.mockwebserver.MockResponse;
38+
import okhttp3.mockwebserver.MockWebServer;
39+
import okhttp3.mockwebserver.RecordedRequest;
4040
import okio.Buffer;
4141
import okio.BufferedSource;
4242

@@ -372,7 +372,7 @@ private ParseHttpRequest generateClientRequest() throws Exception {
372372
private void verifyClientRequest(ParseHttpRequest parseRequest) throws IOException {
373373
assertEquals(server.url("/").toString(), parseRequest.getUrl());
374374
assertEquals(ParseHttpRequest.Method.POST, parseRequest.getMethod());
375-
assertEquals("requestValue", parseRequest.getHeader("requestKey"));
375+
assertEquals("requestValue", parseRequest.getHeader("requestkey"));
376376
assertEquals("application/json", parseRequest.getBody().getContentType());
377377
JSONObject json = new JSONObject();
378378
try {

Parse/src/test/java/com/parse/ParseRESTUserCommandTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import static org.junit.Assert.assertEquals;
2727
import static org.junit.Assert.assertNull;
28-
import static org.junit.Assert.assertTrue;
2928
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
3029

3130
public class ParseRESTUserCommandTest {
@@ -139,7 +138,7 @@ public void testAddAdditionalHeaders() throws Exception {
139138
ParseHttpRequest.Builder requestBuilder = new ParseHttpRequest.Builder();
140139
command.addAdditionalHeaders(requestBuilder);
141140

142-
assertEquals("1", requestBuilder.build().getHeader("X-Parse-Revocable-Session"));
141+
assertEquals("1", requestBuilder.build().getHeader("x-parse-revocable-session"));
143142
}
144143

145144
//endregion

0 commit comments

Comments
 (0)