Skip to content

Commit f2023fd

Browse files
committed
remove authorization header
1 parent 09a6431 commit f2023fd

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/main/java/com/microsoft/graph/core/content/BatchRequestContent.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public InputStream getBatchRequestContent() throws IOException {
178178
return in;
179179
}
180180
}
181+
private static final String AUTHORIZATION_HEADER_KEY = "authorization";
181182
private void writeBatchRequestStep(BatchRequestStep requestStep, JsonWriter writer) throws IOException {
182183
Request request = requestStep.getRequest();
183184
writer.beginObject();
@@ -208,14 +209,14 @@ private void writeBatchRequestStep(BatchRequestStep requestStep, JsonWriter writ
208209
writer.value(rawBodyContent);
209210
}
210211
}
211-
// If 'authorization' header is the only header, do not include headers object
212-
if(!(headers.names().size() == 1 && headers.names().contains("authorization")) && (headers.size() != 0 || requestBody != null)) {
212+
//Remove the header if it is some version of 'authorization'
213+
//RemoveAll utilizes ignoreCase natively
214+
headers = headers.newBuilder().removeAll(AUTHORIZATION_HEADER_KEY).build();
215+
if((headers.size() != 0 || requestBody != null)) {
213216
writer.name(CoreConstants.BatchRequest.HEADERS);
214217
writer.beginObject();
215218
for (int i = 0; i < headers.size(); i++) {
216-
// If multiple headers exist, do not include 'authorization' header
217-
if(!headers.name(i).equals("authorization"))
218-
writer.name(headers.name(i)).value(headers.value(i));
219+
writer.name(headers.name(i)).value(headers.value(i));
219220
}
220221
writer.endObject();
221222
}

src/test/java/com/microsoft/graph/core/content/BatchRequestContentTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.microsoft.graph.core.models.BatchRequestStep;
77
import com.microsoft.graph.core.requests.IBaseClient;
88
import com.microsoft.kiota.HttpMethod;
9-
import com.microsoft.kiota.RequestHeaders;
109
import com.microsoft.kiota.RequestInformation;
1110
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
1211

@@ -278,7 +277,7 @@ void BatchRequestContent_DoNotAddAuthorizationHeader() throws Exception {
278277
requestInfo2.pathParameters = pathParameters2;
279278
requestInfo2.httpMethod = HttpMethod.GET;
280279
// No headers object should be present in the Json body
281-
requestInfo2.headers.add("authorization", longBearerString);
280+
requestInfo2.headers.add("AuthoriZation", longBearerString); // Test with strange casing
282281

283282
BatchRequestContent batchRequestContent = new BatchRequestContent(client);
284283
batchRequestContent.addBatchRequestStep(new BatchRequestStep("1",adapter.convertToNativeRequest(requestInfo)));

0 commit comments

Comments
 (0)