mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-23 23:59:32 -04:00
[Feature] [cURL] Parse query parameters from url in importer (#1726)
* feat(curl): parse parameters from url string * feat(curl): Remove trailing slash after import * feat(curl): Add exception for failing test * feat(curl): Parse params from url in curl importer
This commit is contained in:
committed by
Gregory Schier
parent
61b4c6e78d
commit
e8cefefa57
@@ -9,28 +9,28 @@ import type {
|
||||
import type { Workspace } from '../../models/workspace';
|
||||
import type { OAuth2Token } from '../../models/o-auth-2-token';
|
||||
|
||||
import * as React from 'react';
|
||||
import autobind from 'autobind-decorator';
|
||||
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs';
|
||||
import ContentTypeDropdown from './dropdowns/content-type-dropdown';
|
||||
import AuthDropdown from './dropdowns/auth-dropdown';
|
||||
import KeyValueEditor from './key-value-editor/editor';
|
||||
import RequestHeadersEditor from './editors/request-headers-editor';
|
||||
import RenderedQueryString from './rendered-query-string';
|
||||
import BodyEditor from './editors/body/body-editor';
|
||||
import AuthWrapper from './editors/auth/auth-wrapper';
|
||||
import RequestUrlBar from './request-url-bar.js';
|
||||
import { getAuthTypeName, getContentTypeName } from '../../common/constants';
|
||||
import { deconstructQueryStringToParams, extractQueryStringFromUrl } from 'insomnia-url';
|
||||
import * as React from 'react';
|
||||
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs';
|
||||
import { getAuthTypeName, getContentTypeName } from '../../common/constants';
|
||||
import * as db from '../../common/database';
|
||||
import { hotKeyRefs } from '../../common/hotkeys';
|
||||
import * as models from '../../models';
|
||||
import AuthDropdown from './dropdowns/auth-dropdown';
|
||||
import ContentTypeDropdown from './dropdowns/content-type-dropdown';
|
||||
import AuthWrapper from './editors/auth/auth-wrapper';
|
||||
import BodyEditor from './editors/body/body-editor';
|
||||
import RequestHeadersEditor from './editors/request-headers-editor';
|
||||
import ErrorBoundary from './error-boundary';
|
||||
import Hotkey from './hotkey';
|
||||
import KeyValueEditor from './key-value-editor/editor';
|
||||
import MarkdownPreview from './markdown-preview';
|
||||
import { showModal } from './modals/index';
|
||||
import RequestSettingsModal from './modals/request-settings-modal';
|
||||
import MarkdownPreview from './markdown-preview';
|
||||
import RenderedQueryString from './rendered-query-string';
|
||||
import RequestUrlBar from './request-url-bar.js';
|
||||
import type { Settings } from '../../models/settings';
|
||||
import ErrorBoundary from './error-boundary';
|
||||
import { hotKeyRefs } from '../../common/hotkeys';
|
||||
|
||||
type Props = {
|
||||
// Functions
|
||||
@@ -136,7 +136,7 @@ class RequestPane extends React.PureComponent<Props> {
|
||||
}
|
||||
|
||||
// Remove the search string (?foo=bar&...) from the Url
|
||||
const url = request.url.replace(query, '');
|
||||
const url = request.url.replace(`?${query}`, '');
|
||||
const parameters = [...request.parameters, ...deconstructQueryStringToParams(query)];
|
||||
|
||||
// Only update if url changed
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('Fixtures', () => {
|
||||
const prefix = input.replace(/-input\.[^.]+/, '');
|
||||
const output = `${prefix}-output.json`;
|
||||
|
||||
if (!prefix.includes('simple')) {
|
||||
if (prefix.startsWith('skip')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
"_id": "__REQ_3__",
|
||||
"_type": "request",
|
||||
"parentId": "__WORKSPACE_ID__",
|
||||
"url": "https://insomnia.rest/",
|
||||
"name": "https://insomnia.rest/",
|
||||
"url": "https://insomnia.rest",
|
||||
"name": "https://insomnia.rest",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [],
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
"_id": "__REQ_1__",
|
||||
"_type": "request",
|
||||
"parentId": "__WORKSPACE_ID__",
|
||||
"url": "http://192.168.1.1:9200/executions/_search?pretty",
|
||||
"name": "http://192.168.1.1:9200/executions/_search?pretty",
|
||||
"url": "http://192.168.1.1:9200/executions/_search",
|
||||
"name": "http://192.168.1.1:9200/executions/_search",
|
||||
"method": "POST",
|
||||
"body": {
|
||||
"mimeType": "",
|
||||
"text": "{\"query\":{\"match_all\":{}}}"
|
||||
},
|
||||
"parameters": [],
|
||||
"parameters": [{ "name": "pretty", "disabled": false, "value": "" }],
|
||||
"headers": [],
|
||||
"authentication": {}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
"_id": "__REQ_1__",
|
||||
"_type": "request",
|
||||
"parentId": "__WORKSPACE_ID__",
|
||||
"url": "https://www.google.com/",
|
||||
"name": "https://www.google.com/",
|
||||
"url": "https://www.google.com",
|
||||
"name": "https://www.google.com",
|
||||
"method": "GET",
|
||||
"body": {},
|
||||
"parameters": [],
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
"_id": "__REQ_1__",
|
||||
"_type": "request",
|
||||
"parentId": "__WORKSPACE_ID__",
|
||||
"url": "https://insomnia.rest/",
|
||||
"name": "https://insomnia.rest/",
|
||||
"url": "https://insomnia.rest",
|
||||
"name": "https://insomnia.rest",
|
||||
"method": "POST",
|
||||
"body": {
|
||||
"mimeType": "application/x-www-form-urlencoded",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { parse } = require('shell-quote');
|
||||
const { URL } = require('url');
|
||||
|
||||
let requestCount = 1;
|
||||
|
||||
@@ -128,8 +129,19 @@ function importArgs(args) {
|
||||
// Build the request //
|
||||
// ~~~~~~~~~~~~~~~~~ //
|
||||
|
||||
// Url
|
||||
const url = getPairValue(pairs, singletons[0] || '', 'url');
|
||||
// Url & parameters
|
||||
let parameters = [];
|
||||
let url = '';
|
||||
|
||||
try {
|
||||
const urlObject = new URL(getPairValue(pairs, singletons[0] || '', 'url'));
|
||||
parameters = Array.from(urlObject.searchParams.entries()).map(([key, value]) => ({
|
||||
name: key,
|
||||
value,
|
||||
disabled: false,
|
||||
}));
|
||||
url = urlObject.href.replace(urlObject.search, '').replace(/\/$/, '');
|
||||
} catch (err) {}
|
||||
|
||||
// Authentication
|
||||
const [username, password] = getPairValue(pairs, '', 'u', 'user').split(/:(.*)$/);
|
||||
@@ -191,13 +203,14 @@ function importArgs(args) {
|
||||
});
|
||||
|
||||
// Body
|
||||
let parameters = [];
|
||||
let body = mimeType ? { mimeType: mimeType } : {};
|
||||
if (textBody && bodyAsGET) {
|
||||
parameters = textBody.split('&').map(v => {
|
||||
const bodyParams = textBody.split('&').map(v => {
|
||||
const [name, value] = v.split('=');
|
||||
return { name: name || '', value: value || '' };
|
||||
});
|
||||
|
||||
parameters.push(...bodyParams);
|
||||
} else if (textBody && mimeType === 'application/x-www-form-urlencoded') {
|
||||
body.params = textBody.split('&').map(v => {
|
||||
const [name, value] = v.split('=');
|
||||
|
||||
Reference in New Issue
Block a user