Skip to content

Commit

Permalink
Support any method for PowerShell (#320)
Browse files Browse the repository at this point in the history
* Support any method for PowerShell

* fix test

---------

Co-authored-by: Filipe Freire <[email protected]>
  • Loading branch information
verhovsky and filfreire authored Jul 12, 2024
1 parent e99422a commit 29947cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/targets/powershell/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
allHeaders,
}) => {
const { push, join } = new CodeBuilder();
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];

if (!methods.includes(method.toUpperCase())) {
return 'Method not supported';
}
const methods = [
'DEFAULT',
'DELETE',
'GET',
'HEAD',
'MERGE',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'TRACE'
];
const methodArg = methods.includes(method.toUpperCase()) ? '-Method' : '-CustomMethod';

const commandOptions = [];

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

push(`$response = ${command} -Uri '${fullUrl}' -Method ${method} ${commandOptions.join(' ')}`);
push(`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`);
return join();
};
return convert;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Method not supported
$response = Invoke-RestMethod -Uri 'http://mockbin.com/har' -CustomMethod PROPFIND
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Method not supported
$response = Invoke-WebRequest -Uri 'http://mockbin.com/har' -CustomMethod PROPFIND

0 comments on commit 29947cc

Please sign in to comment.