Skip to content

Commit

Permalink
Changes after build
Browse files Browse the repository at this point in the history
  • Loading branch information
condorcorde committed Feb 1, 2024
1 parent fa5ddb3 commit c5d6220
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Invoke-ApiClient {
}

# accept, content-type headers
$Accept = SelectHeaders -Headers $Accepts
$Accept = SelectHeaders -Headers $Accepts -Multiple
if ($Accept) {
$HeaderParameters['Accept'] = $Accept
}
Expand Down Expand Up @@ -182,24 +182,30 @@ function Invoke-ApiClient {
}
}

# Select JSON MIME if present, otherwise choose the first one if available
# Select multiple types for Accept header
# Select JSON MIME if present, otherwise choose the first one if available for Content-Type header
function SelectHeaders {
Param(
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[String[]]$Headers
[String[]]$Headers,
[Parameter(Mandatory=$false)]
[switch]$Multiple
)

foreach ($Header in $Headers) {
if (IsJsonMIME -MIME $Header) {
return $Header
}
}

if (!($Headers) -or $Headers.Count -eq 0) {
return $null
}

if ($Multiple) {
return [string]::Join(', ', $Headers) # join multiple types if they are provided
} else {
return $Headers[0] # return the first one
foreach ($Header in $Headers) {
if (IsJsonMIME -MIME $Header) {
return $Header # return the first type matching a JSON MIME
}
}
return $Headers[0] # else return the first one
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Invoke-PSApiClient {
}

# accept, content-type headers
$Accept = SelectHeaders -Headers $Accepts
$Accept = SelectHeaders -Headers $Accepts -Multiple
if ($Accept) {
$HeaderParameters['Accept'] = $Accept
}
Expand Down Expand Up @@ -198,24 +198,30 @@ function Invoke-PSApiClient {
}
}

# Select JSON MIME if present, otherwise choose the first one if available
# Select multiple types for Accept header
# Select JSON MIME if present, otherwise choose the first one if available for Content-Type header
function SelectHeaders {
Param(
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[String[]]$Headers
[String[]]$Headers,
[Parameter(Mandatory=$false)]
[switch]$Multiple
)

foreach ($Header in $Headers) {
if (IsJsonMIME -MIME $Header) {
return $Header
}
}

if (!($Headers) -or $Headers.Count -eq 0) {
return $null
}

if ($Multiple) {
return [string]::Join(', ', $Headers) # join multiple types if they are provided
} else {
return $Headers[0] # return the first one
foreach ($Header in $Headers) {
if (IsJsonMIME -MIME $Header) {
return $Header # return the first type matching a JSON MIME
}
}
return $Headers[0] # else return the first one
}
}

Expand Down

0 comments on commit c5d6220

Please sign in to comment.