Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow callers of Invoke-GHRestMethod[MultipleResult] to specify addit…
…ional headers

When experimenting with the the notifications API, it was necessary
to be able to specify an additional header (If-Modified-Since).

Making this support generic by allowing callers to specify any number
of additional headers to be included with the REST request.
  • Loading branch information
HowardWolosky committed Mar 17, 2021
commit 8ccbdc294ce3292936d04eb698eaabf3d6fc4c89
19 changes: 19 additions & 0 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function Invoke-GHRestMethod
be configured correctly automatically. You should only specify this under advanced
situations (like if the extension of InFile is of a type unknown to this module).

.PARAMETER AdditionalHeader
Allows the caller to specify any number of additional headers that should be added to
the request.

.PARAMETER ExtendedResult
If specified, the result will be a PSObject that contains the normal result, along with
the response code and other relevant header detail content.
Expand Down Expand Up @@ -135,6 +139,8 @@ function Invoke-GHRestMethod

[string] $ContentType = $script:defaultJsonBodyContentType,

[HashTable] $AdditionalHeader = @{},

[switch] $ExtendedResult,

[switch] $Save,
Expand Down Expand Up @@ -228,6 +234,12 @@ function Invoke-GHRestMethod
'User-Agent' = 'PowerShellForGitHub'
}

# Add any additional headers
foreach ($header in $AdditionalHeader.Keys.GetEnumerator())
{
$headers.Add($header, $AdditionalHeader.$header)
}

$AccessToken = Get-AccessToken -AccessToken $AccessToken
if (-not [String]::IsNullOrEmpty($AccessToken))
{
Expand Down Expand Up @@ -588,6 +600,10 @@ function Invoke-GHRestMethodMultipleResult
Specify the media type in the Accept header. Different types of commands may require
different media types.

.PARAMETER AdditionalHeader
Allows the caller to specify any number of additional headers that should be added to
all of the requests made.

.PARAMETER AccessToken
If provided, this will be used as the AccessToken for authentication with the
REST Api as opposed to requesting a new one.
Expand Down Expand Up @@ -637,6 +653,8 @@ function Invoke-GHRestMethodMultipleResult

[string] $AcceptHeader = $script:defaultAcceptHeader,

[hashtable] $AdditionalHeader = @{},

[string] $AccessToken,

[string] $TelemetryEventName = $null,
Expand Down Expand Up @@ -675,6 +693,7 @@ function Invoke-GHRestMethodMultipleResult
'Method' = 'Get'
'Description' = $currentDescription
'AcceptHeader' = $AcceptHeader
'AdditionalHeader' = $AdditionalHeader
'ExtendedResult' = $true
'AccessToken' = $AccessToken
'TelemetryProperties' = $telemetryProperties
Expand Down