Skip to content

Commit 9cae2b7

Browse files
prepare 3.2.4 release (#18)
1 parent acf3e6a commit 9cae2b7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Requestor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as errors from './errors';
33
import * as messages from './messages';
44
import promiseCoalescer from './promiseCoalescer';
55

6-
const json = 'application/json';
6+
const jsonContentType = 'application/json';
77

88
function getResponseError(result) {
99
if (result.status === 404) {
@@ -33,7 +33,7 @@ export default function Requestor(platform, options, environment) {
3333
const method = body ? 'REPORT' : 'GET';
3434
const headers = utils.getLDHeaders(platform, options);
3535
if (body) {
36-
headers['Content-Type'] = 'application/json';
36+
headers['Content-Type'] = jsonContentType;
3737
}
3838

3939
let coalescer = activeRequests[endpoint];
@@ -49,7 +49,7 @@ export default function Requestor(platform, options, environment) {
4949
const p = req.promise.then(
5050
result => {
5151
if (result.status === 200) {
52-
if (result.header('content-type') && result.header('content-type').lastIndexOf(json) === 0) {
52+
if (result.header('content-type') && result.header('content-type').startsWith(jsonContentType)) {
5353
return JSON.parse(result.body);
5454
} else {
5555
const message = messages.invalidContentType(result.header('content-type') || '');

src/__tests__/Requestor-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,27 @@ describe('Requestor', () => {
238238
});
239239
});
240240

241+
it('allows JSON content type with charset', async () => {
242+
await withServer(async (baseConfig, server) => {
243+
server.byDefault(respond(200, { 'content-type': 'application/json; charset=utf-8' }, '{}'));
244+
const requestor = Requestor(platform, baseConfig, env);
245+
246+
const result = await requestor.fetchFlagSettings(user);
247+
expect(result).toEqual({});
248+
});
249+
});
250+
251+
it('allows extra JSON content type header', async () => {
252+
await withServer(async (baseConfig, server) => {
253+
// this could happen if a proxy/gateway interpolated its own content-type header; https://github.com/launchdarkly/js-client-sdk/issues/205
254+
server.byDefault(respond(200, { 'content-type': 'application/json, application/json; charset=utf-8' }, '{}'));
255+
const requestor = Requestor(platform, baseConfig, env);
256+
257+
const result = await requestor.fetchFlagSettings(user);
258+
expect(result).toEqual({});
259+
});
260+
});
261+
241262
it('returns error for non-JSON content type', async () => {
242263
await withServer(async (baseConfig, server) => {
243264
server.byDefault(respond(200, { 'content-type': 'text/plain' }, 'sorry'));

0 commit comments

Comments
 (0)