Skip to content

Commit 8006696

Browse files
committed
fix: correctly get request content type
1 parent 9548883 commit 8006696

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils/XhrNetworkInterceptor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import InstabugConstants from './InstabugConstants';
2+
import { stringifyIfNotString } from './InstabugUtils';
23

34
export type ProgressCallback = (totalBytesSent: number, totalBytesExpectedToSend: number) => void;
45
export type NetworkDataCallback = (data: NetworkData) => void;
@@ -80,7 +81,12 @@ export default {
8081
};
8182

8283
XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
83-
network.requestHeaders[header] = typeof value === 'string' ? value : JSON.stringify(value);
84+
// According to the HTTP RFC, headers are case-insensitive, so we convert
85+
// them to lower-case to make accessing headers predictable.
86+
// This avoid issues like failing to get the Content-Type header for a request
87+
// because the header is set as 'Content-Type' instead of 'content-type'.
88+
const key = header.toLowerCase();
89+
network.requestHeaders[key] = stringifyIfNotString(value);
8490
originalXHRSetRequestHeader.apply(this, [header, value]);
8591
};
8692

0 commit comments

Comments
 (0)