GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add explicit ContentType detection to Invoke-RestMethod by dantraMSFT · Pull Request #4692 · PowerShell/PowerShell Conversation
|
|
|
||
| [switch] $UseBasicParsing | ||
| ) | ||
| $result = [PSObject]@{Output = $null; Error = $null; Encoding = $null; Content = $null} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
i think that '[PSObject]' should probably be '[PSCustomObject]' - the [PSObject] doesn't actually convert the type away from a hashtable. So, [PSObject] can be removed, or changed to [PSCustomObject]
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will do.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| if ($result.Encoding -eq $null) | ||
| { | ||
| throw "Encoding not found in verbose output. Lines: $($result).Verbose.Count Content:$($result.Verbose)" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
$($result).Verbose.Count should be $($result.Verbose.Count)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll fix it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| $result.Error = $_ | select-object * | Out-String | ||
| } | ||
| finally |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
since the $TESTDRIVE is removed by pester, you only need set the verbosePreference back.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The test drive isn't cleared until the end of the context block. line 322 uses a test for the file's existence. With the current configuration, subsequent calls to ExecuteRestMethod could result in false positives for the test on line 322 if the file is not removed at the end at the end of the function. This cleanup action would need to remain or the filename generated on each call to ExecuteRestMethod would need to be unique.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As Mark Kraus (@markekraus) indicates, this is by design and simpler than generating file names.
it also occurs to me that I shouldn't be relying on test/context lifetime for this function; I don't know if it will be called once or multiple times.
I'll be leaving the code as is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| It "Verifies Invoke-WebRequest detects charset meta value when newlines are encountered in the element." { | ||
| $output = @' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
just a question, would:
"<html>`n<head>`n<meta`n charset=""Unicode"" `n>`n</head>`n</html>`n"
be the same?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I find the HERE string much easier to read and it avoids me making silly escaping errors.
I'll be leaving it as is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| $VerbosePreference = $verbosePreferenceSave | ||
| if (Test-Path -Path $verboseFile) | ||
| { | ||
| Remove-Item -Path $verboseFile -ErrorAction Ignore |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Usualy we use SilentlyContinue not Ignore.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I'll change it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Closed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return $result | ||
| } | ||
|
|
||
| [string] $verboseEncodingPrefix = 'Content encoding: ' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Move $verboseEncodingPrefix into the function body so it does not become orphaned.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think I want a locally scoped variable that has to be initialized each call.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fair enough
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Artifacts from merge should be removed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return $result | ||
| } | ||
|
|
||
| function GetSelfSignedCert { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This function is no longer needed it was removed in #4622
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it looks like Dongbo removed it when he merged.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
yes. the commit came in after I hit submit. both of these comments in this review are fixed now
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| #endregion SkipHeaderVerification Tests | ||
|
|
||
| #region Certificate Authentication Tests |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Everything in this region was removed in #4622
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mark Kraus (@markekraus) thanks! Dan Travison (@dantraMSFT) can you go through the file |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Dongbo Wang (@daxian-dbw) the merge looks fine and all tests pass on my systems. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
) This change removes the call to `ContentHelper.GetEncoding` since it's logic for returning a default encoding when a ContentType header is not found disables subsequent checks for meta charset definitions. All variations of the Invoke-WebRequest tests have been mirrored for Invoke-RestMethod. Verbose output is used to verify the encoding since Invoke-RestMethod returns the JSON content directly instead of a response object. (See ExecuteRestMethod)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Webcmdlets should parse the <html><head><meta charset="foo"> attribute for the correct encoding if not in http header
There was an error while loading. Please reload this page.