Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 1f88b93

Browse files
author
Peter Nied
committed
Simplify to try and then update to override header
1 parent 4152fdd commit 1f88b93

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

onedrivesdk/src/main/java/com/onedrive/sdk/http/UrlConnection.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222

2323
package com.onedrive.sdk.http;
2424

25-
import android.os.Build;
26-
2725
import com.onedrive.sdk.options.HeaderOption;
2826

2927
import java.io.IOException;
3028
import java.io.InputStream;
3129
import java.io.OutputStream;
3230
import java.net.HttpURLConnection;
31+
import java.net.ProtocolException;
3332
import java.util.HashMap;
34-
import java.util.Locale;
3533
import java.util.Map;
3634

3735
/**
@@ -61,16 +59,13 @@ public UrlConnection(final IHttpRequest request) throws IOException {
6159
mConnection.addRequestProperty(header.getName(), header.getValue());
6260
}
6361

64-
if (request.getHttpMethod() == HttpMethod.PATCH
65-
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
66-
if (request.getRequestUrl().getAuthority().toLowerCase(Locale.ROOT).startsWith("api.onedrive.com")) {
67-
mConnection.setRequestMethod(HttpMethod.POST.toString());
68-
mConnection.addRequestProperty("X-HTTP-Method-Override", "PATCH");
69-
} else {
70-
mConnection.setRequestMethod(HttpMethod.PUT.toString());
71-
}
72-
} else {
62+
try {
7363
mConnection.setRequestMethod(request.getHttpMethod().toString());
64+
} catch (final ProtocolException ignored ){
65+
// Some HTTP verbs are not supported by older http implementations, use method override as an alternative
66+
mConnection.setRequestMethod(HttpMethod.POST.toString());
67+
mConnection.addRequestProperty("X-HTTP-Method-Override", request.getHttpMethod().toString());
68+
mConnection.addRequestProperty("X-HTTP-Method", request.getHttpMethod().toString());
7469
}
7570
}
7671

0 commit comments

Comments
 (0)