Guess content type if no header present

Summary:
Changelog: [Network] The network plugin will now detect utf-8 strings if no content header is present

Fixes https://github.com/facebook/flipper/issues/2406

Reviewed By: nikoant

Differential Revision: D29388968

fbshipit-source-id: 7017828a5f3f28dcf220eeda1d30888f1fc5f07a
This commit is contained in:
Michel Weststrate
2021-06-25 07:22:15 -07:00
committed by Facebook GitHub Bot
parent 2b0ce88c22
commit 9f27b374f4
4 changed files with 79 additions and 27 deletions

View File

@@ -9,7 +9,7 @@
import {readFile} from 'fs';
import path from 'path';
import {decodeBody} from '../utils';
import {decodeBody, isTextual} from '../utils';
import {ResponseInfo} from '../types';
import {promisify} from 'util';
import {readFileSync} from 'fs';
@@ -139,6 +139,19 @@ describe('network data encoding', () => {
});
});
test('detects utf8 strings in binary arrays', async () => {
const binaryBuffer = readFileSync(
path.join(__dirname, 'fixtures', 'tiny_logo.png'),
);
const textBuffer = readFileSync(
path.join(__dirname, 'fixtures', 'donating.md'),
);
const textBuffer2 = readFileSync(__filename);
expect(isTextual(undefined, binaryBuffer)).toBe(false);
expect(isTextual(undefined, textBuffer)).toBe(true);
expect(isTextual(undefined, textBuffer2)).toBe(true);
});
test('binary data gets serialized correctly', async () => {
const tinyLogoExpected = readFileSync(
path.join(__dirname, 'fixtures', 'tiny_logo.png'),