fix problem with mock request data (#2340)

Summary:
Network Plugin - When creating a mock request from a selected request, the request data is not in the proper format.  It is decoded instead of just being copied from the call (which has already been decoded properly).  This PR fixes that problem.

Below is a screenshot showing the problem (which occurs for all text response data):

![image](https://user-images.githubusercontent.com/337874/118744068-423e3b80-b819-11eb-9076-216459517fdb.png)

## Changelog

Network Plugin - Fix problem with decoding request data for mocks copied from selection

Pull Request resolved: https://github.com/facebook/flipper/pull/2340

Test Plan:
Using the sample Android app, issue a network request

In Flipper, create a mock for the network request by selecting it and using the "Copy Selected Calls" function in the mock

Verify that the request data is readable:

![image](https://user-images.githubusercontent.com/337874/118744220-8af5f480-b819-11eb-9206-0fa40e7d7e46.png)

Note:

Testing was done using the sample app which uses responses with JSON data.  I was not able to provide testing for other types of calls, specifically calls that would return binary data.

Reviewed By: passy

Differential Revision: D28533224

Pulled By: mweststrate

fbshipit-source-id: ce11d23ade60843c110286f7a5bbeba91febbcf0
This commit is contained in:
bizzguy
2021-05-19 03:14:37 -07:00
committed by Facebook GitHub Bot
parent 7572178f25
commit b378d8b946
2 changed files with 7 additions and 12 deletions

View File

@@ -39,7 +39,7 @@ export interface NetworkRouteManager {
modifyRoute(id: string, routeChange: Partial<Route>): void;
removeRoute(id: string): void;
enableRoute(id: string): void;
copyHighlightedCalls(): void;
copySelectedCalls(): void;
importRoutes(): void;
exportRoutes(): void;
clearRoutes(): void;
@@ -52,7 +52,7 @@ export const nullNetworkRouteManager: NetworkRouteManager = {
modifyRoute(_id: string, _routeChange: Partial<Route>) {},
removeRoute(_id: string) {},
enableRoute(_id: string) {},
copyHighlightedCalls() {},
copySelectedCalls() {},
importRoutes() {},
exportRoutes() {},
clearRoutes() {},
@@ -109,7 +109,7 @@ export function createNetworkManager(
}
informClientMockChange(routes.get());
},
copyHighlightedCalls() {
copySelectedCalls() {
tableManagerRef.current?.getSelectedItems().forEach((request) => {
// convert headers
const headers: {[id: string]: Header} = {};
@@ -117,14 +117,9 @@ export function createNetworkManager(
headers[e.key] = e;
});
// convert data TODO: we only want this for non-binary data! See D23403095
// no need to convert data, already converted when real call was created
const responseData =
request && request.responseData
? decodeBody(
request.responseHeaders ?? [],
bodyAsString(request.responseData),
)
: '';
request && request.responseData ? request.responseData : '';
const newNextRouteId = nextRouteId.get();
routes.update((draft) => {