New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds parameter sets to web cmdlets to allow for standard and non-stan… #3142
Changes from 3 commits
7c11001
8f25fd9
ecf7624
51fb2fb
5d6763b
f5db053
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,10 +84,19 @@ internal virtual WebRequest GetRequest(Uri uri) | |
request.Proxy = WebSession.Proxy; | ||
} | ||
|
||
// set the method if the parameter was provided | ||
if (WebRequestMethod.Default != Method) | ||
switch (ParameterSetName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had this simplified to this. Since CustomMethod will always be null or a real string (param validation) checking for $null should be enough. // set the custom method if the parameter was provided
if(CustomMethod != null)
{
request.Method = CustomMethod.ToUpperInvariant();
}
else
{
// set the method if the parameter was provided
if (WebRequestMethod.Default != Method)
{
request.Method = Method.ToString().ToUpperInvariant();
}
} |
||
{ | ||
request.Method = Method.ToString().ToUpperInvariant(); | ||
case "StandardMethod": | ||
if (WebRequestMethod.Default != Method) | ||
{ | ||
// set the method if the parameter was provided | ||
request.Method = Method.ToString().ToUpperInvariant(); | ||
} | ||
break; | ||
case "CustomMethod": | ||
// set the method if the parameter was provided | ||
request.Method = CustomMethod.ToUpperInvariant(); | ||
break; | ||
} | ||
|
||
// pull in http specific properties | ||
|
@@ -248,7 +257,8 @@ internal virtual void FillRequestStream(WebRequest request) | |
request.ContentType = ContentType; | ||
} | ||
// ContentType == null | ||
else if (Method == WebRequestMethod.Post) | ||
else if ((IsStandardMethodSet() && Method == WebRequestMethod.Post) | ||
|| (IsCustomMethodSet() && CustomMethod.ToUpperInvariant() == "POST")) | ||
{ | ||
// Win8:545310 Invoke-WebRequest does not properly set MIME type for POST | ||
if (String.IsNullOrEmpty(request.ContentType)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,6 +399,23 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |
$result = ExecuteWebCommand -command $command | ||
$result.Error | Should BeNullOrEmpty | ||
} | ||
|
||
It "Validate StandardMethod and CustomMethod parameter sets" { | ||
|
||
#Validate that parameter sets are functioning correctly | ||
$command = "Invoke-RestMethod -Uri 'http://sandbox.lee.io/method.php' -Method GET -CustomMethod 'TEST'" | ||
$result = ExecuteWebCommand -command $command | ||
$result.Error | Should Not BeNullOrEmpty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored test to utilise |
||
} | ||
|
||
It "Validate CustomMethod parameter set method is passed" { | ||
|
||
#Validate that parameter sets are functioning correctly | ||
$command = "Invoke-RestMethod -Uri 'http://sandbox.lee.io/method.php' -CustomMethod 'TEST'" | ||
$result = ExecuteWebCommand -command $command | ||
$result.Error | Should BeNullOrEmpty | ||
($result.Output | ConvertFrom-Json).method | Should Be "TEST" | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you added code explicitly for when CustomMethod is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests now added for this |
||
Describe "Invoke-RestMethod tests" -Tags "Feature" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make this validate on input and removed the checks for
IsNullOrEmpty
. Also adding an alias now would be nice.