Skip to content

Commit 74b0a4f

Browse files
authored
Merge pull request #467 from microsoftgraph/bugfix/content-type-post-override
- fixes a bug where the content type of a post request would be forcibly overridden
2 parents 6e7acc8 + cd3dab0 commit 74b0a4f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/com/microsoft/graph/http/CoreHttpProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ public <Result, Body> Request getHttpRequest(final IHttpRequest request,
260260
// This ensures that the Content-Length header is properly set
261261
if (request.getHttpMethod() == HttpMethod.POST) {
262262
bytesToWrite = new byte[0];
263-
contenttype = Constants.BINARY_CONTENT_TYPE;
263+
if(contenttype == null) {
264+
contenttype = Constants.BINARY_CONTENT_TYPE;
265+
}
264266
}
265267
else {
266268
bytesToWrite = null;

src/test/java/com/microsoft/graph/functional/UserTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
package com.microsoft.graph.functional;
22

3+
import static org.junit.Assert.assertEquals;
34
import static org.junit.Assert.assertNotNull;
45

56
import java.io.File;
67
import java.io.FileInputStream;
78
import java.io.InputStream;
9+
import java.util.ArrayList;
810
import java.util.List;
911

1012
import org.junit.Before;
1113
import org.junit.Ignore;
1214
import org.junit.Test;
1315

16+
import okhttp3.Request;
17+
18+
import com.microsoft.graph.http.HttpMethod;
1419
import com.microsoft.graph.models.extensions.Drive;
1520
import com.microsoft.graph.models.extensions.DriveItem;
1621
import com.microsoft.graph.models.extensions.IGraphServiceClient;
1722
import com.microsoft.graph.models.extensions.ProfilePhoto;
1823
import com.microsoft.graph.models.extensions.User;
24+
import com.microsoft.graph.options.HeaderOption;
25+
import com.microsoft.graph.options.Option;
1926
import com.microsoft.graph.requests.extensions.IContactCollectionPage;
2027
import com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage;
2128
import com.microsoft.graph.requests.extensions.IDriveItemCollectionPage;
@@ -164,4 +171,18 @@ public void meMemberof() {
164171
assertNotNull(page);
165172
}
166173

174+
@Test
175+
public void emptyPostContentType() {
176+
final String contentTypeValue = "application/json";
177+
final HeaderOption ctype = new HeaderOption("Content-Type", contentTypeValue);
178+
final ArrayList<Option> options = new ArrayList<>();
179+
options.add(ctype);
180+
final Request request = graphServiceClient.me()
181+
.revokeSignInSessions()
182+
.buildRequest(options)
183+
.withHttpMethod(HttpMethod.POST)
184+
.getHttpRequest();
185+
assertEquals(contentTypeValue, request.body().contentType().toString());
186+
}
187+
167188
}

0 commit comments

Comments
 (0)