microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
smoke-actionbar-use-packager-helper

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/networkInspector/requestBodyFormatters/formUrlencodedFormatter.ts

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