Skip to content

Commit a2329d6

Browse files
Allow callers of Invoke-GHRestMethod[MultipleResult] to specify additional headers (#319)
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.
1 parent f7a60c7 commit a2329d6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

GitHubCore.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function Invoke-GHRestMethod
6868
be configured correctly automatically. You should only specify this under advanced
6969
situations (like if the extension of InFile is of a type unknown to this module).
7070
71+
.PARAMETER AdditionalHeader
72+
Allows the caller to specify any number of additional headers that should be added to
73+
the request.
74+
7175
.PARAMETER ExtendedResult
7276
If specified, the result will be a PSObject that contains the normal result, along with
7377
the response code and other relevant header detail content.
@@ -135,6 +139,8 @@ function Invoke-GHRestMethod
135139

136140
[string] $ContentType = $script:defaultJsonBodyContentType,
137141

142+
[HashTable] $AdditionalHeader = @{},
143+
138144
[switch] $ExtendedResult,
139145

140146
[switch] $Save,
@@ -228,6 +234,12 @@ function Invoke-GHRestMethod
228234
'User-Agent' = 'PowerShellForGitHub'
229235
}
230236

237+
# Add any additional headers
238+
foreach ($header in $AdditionalHeader.Keys.GetEnumerator())
239+
{
240+
$headers.Add($header, $AdditionalHeader.$header)
241+
}
242+
231243
$AccessToken = Get-AccessToken -AccessToken $AccessToken
232244
if (-not [String]::IsNullOrEmpty($AccessToken))
233245
{
@@ -588,6 +600,10 @@ function Invoke-GHRestMethodMultipleResult
588600
Specify the media type in the Accept header. Different types of commands may require
589601
different media types.
590602
603+
.PARAMETER AdditionalHeader
604+
Allows the caller to specify any number of additional headers that should be added to
605+
all of the requests made.
606+
591607
.PARAMETER AccessToken
592608
If provided, this will be used as the AccessToken for authentication with the
593609
REST Api as opposed to requesting a new one.
@@ -637,6 +653,8 @@ function Invoke-GHRestMethodMultipleResult
637653

638654
[string] $AcceptHeader = $script:defaultAcceptHeader,
639655

656+
[hashtable] $AdditionalHeader = @{},
657+
640658
[string] $AccessToken,
641659

642660
[string] $TelemetryEventName = $null,
@@ -675,6 +693,7 @@ function Invoke-GHRestMethodMultipleResult
675693
'Method' = 'Get'
676694
'Description' = $currentDescription
677695
'AcceptHeader' = $AcceptHeader
696+
'AdditionalHeader' = $AdditionalHeader
678697
'ExtendedResult' = $true
679698
'AccessToken' = $AccessToken
680699
'TelemetryProperties' = $telemetryProperties

0 commit comments

Comments
 (0)