From 525e8b19fb98d870378787eb824f6cb882e1a05a Mon Sep 17 00:00:00 2001 From: Denis Colliot Date: Tue, 18 May 2021 13:47:16 -0700 Subject: [PATCH] Detect JSON API content type ('application/vnd.api+json') as textual content (#2337) Summary: Network requests and responses using JSON API content type of pattern `application/vnd.api+json` (see https://jsonapi.org/#mime-types) are currently treated as binary data. They should be treated as textual content. ## Changelog Add regular expression to detect JSON content types. Pull Request resolved: https://github.com/facebook/flipper/pull/2337 Test Plan: Using an API that return `Content-Type` of pattern `application/vnd.api+json`, verify that the response data in sidebar appears as text rather than `(binary data)`. Reviewed By: passy Differential Revision: D28513547 Pulled By: mweststrate fbshipit-source-id: 3335b7eeb63c2429c2245113c8c83bd7e08a9420 --- desktop/plugins/public/network/utils.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desktop/plugins/public/network/utils.tsx b/desktop/plugins/public/network/utils.tsx index 81daac04e..2560bd3f2 100644 --- a/desktop/plugins/public/network/utils.tsx +++ b/desktop/plugins/public/network/utils.tsx @@ -26,6 +26,9 @@ export function getHeaderValue( return ''; } +// Matches `application/json` and `application/vnd.api.v42+json` (see https://jsonapi.org/#mime-types) +const jsonContentTypeRegex = new RegExp('application/(json|.+\\+json)'); + export function isTextual(headers?: Array
): boolean { const contentType = getHeaderValue(headers, 'Content-Type'); if (!contentType) { @@ -36,7 +39,7 @@ export function isTextual(headers?: Array
): boolean { return ( contentType.startsWith('text/') || contentType.startsWith('application/x-www-form-urlencoded') || - contentType.startsWith('application/json') || + jsonContentTypeRegex.test(contentType) || contentType.startsWith('multipart/') || contentType.startsWith('message/') || contentType.startsWith('image/svg') ||