Skip to content

Commit 29947cc

Browse files
verhovskyfilfreire
andauthored
Support any method for PowerShell (Kong#320)
* Support any method for PowerShell * fix test --------- Co-authored-by: Filipe Freire <[email protected]>
1 parent e99422a commit 29947cc

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/targets/powershell/common.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
1616
allHeaders,
1717
}) => {
1818
const { push, join } = new CodeBuilder();
19-
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
20-
21-
if (!methods.includes(method.toUpperCase())) {
22-
return 'Method not supported';
23-
}
19+
const methods = [
20+
'DEFAULT',
21+
'DELETE',
22+
'GET',
23+
'HEAD',
24+
'MERGE',
25+
'OPTIONS',
26+
'PATCH',
27+
'POST',
28+
'PUT',
29+
'TRACE'
30+
];
31+
const methodArg = methods.includes(method.toUpperCase()) ? '-Method' : '-CustomMethod';
2432

2533
const commandOptions = [];
2634

@@ -65,7 +73,7 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
6573
commandOptions.push(`-Body '${postData.text}'`);
6674
}
6775

68-
push(`$response = ${command} -Uri '${fullUrl}' -Method ${method} ${commandOptions.join(' ')}`);
76+
push(`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`);
6977
return join();
7078
};
7179
return convert;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Method not supported
1+
$response = Invoke-RestMethod -Uri 'http://mockbin.com/har' -CustomMethod PROPFIND
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Method not supported
1+
$response = Invoke-WebRequest -Uri 'http://mockbin.com/har' -CustomMethod PROPFIND

0 commit comments

Comments
 (0)