microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
caa0dc5eb84731caee69a4d06915c6a3856ec289

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/networkInspector/requestBodyFormatters/formUrlencodedFormatter.ts

39lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { IFormatter, decodeBody, FormattedBody } from "./requestBodyFormatter";
5import { OutputChannelLogger } from "../../log/OutputChannelLogger";
6import { Request } from "../networkMessageData";
7import * as querystring from "querystring";
8
9/**
10 * @preserve
11 * Start region: the code is borrowed from https://github.com/facebook/flipper/blob/v0.79.1/desktop/plugins/network/RequestDetails.tsx#L769-L785
12 *
13 * Copyright (c) Facebook, Inc. and its affiliates.
14 *
15 * This source code is licensed under the MIT license found in the
16 * LICENSE file in the root directory of this source tree.
17 *
18 * @format
19 */
20
21export class FormUrlencodedFormatter implements IFormatter {
22 constructor(private logger: OutputChannelLogger) {}
23
24 public formatRequest(request: Request, contentType: string): FormattedBody | null {
25 if (contentType.startsWith("application/x-www-form-urlencoded")) {
26 const decoded = decodeBody(request, this.logger);
27 if (!decoded) {
28 return null;
29 }
30 return querystring.parse(decoded);
31 }
32 return null;
33 }
34}
35
36/**
37 * @preserve
38 * End region: https://github.com/facebook/flipper/blob/v0.79.1/desktop/plugins/network/RequestDetails.tsx#L769-L785
39 */
40