microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
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 | |
| 4 | import { IFormatter, decodeBody, FormattedBody } from "./requestBodyFormatter"; |
| 5 | import { OutputChannelLogger } from "../../log/OutputChannelLogger"; |
| 6 | import { Request } from "../networkMessageData"; |
| 7 | import * 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 | |
| 21 | export 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 | |