Skip to content

Commit 6a2ae59

Browse files
docs(powershell): correct the header-collection note in Get-FalconRegionHeader
The note claimed the success path yields "a Dictionary, so ContainsKey". That was an assumption. Measured on Windows PowerShell 5.1.26100.9168: Invoke-WebRequest returns a body-less 3xx as Microsoft.PowerShell.Commands.WebResponseObject, whose Content is a Byte[] — which is precisely why the old code failed inside ConvertFrom-Json before it could reach the region logic. The note now distinguishes what was measured on each platform and path from what rests on documentation, and no longer names a type nothing verified. Comment only; no behaviour change. The functional test still passes on PowerShell 7.6.5 and on 5.1.
1 parent 6b54ff1 commit 6a2ae59

3 files changed

Lines changed: 51 additions & 30 deletions

File tree

powershell/install/falcon_windows_install.ps1

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,23 @@ begin {
207207
}
208208

209209
function Get-FalconRegionHeader($Response) {
210-
# Reads X-Cs-Region off a response whose header collection type varies by
211-
# platform and by which code path produced it. The wrong accessor fails
212-
# quietly rather than loudly, so probe instead of assuming. Measured:
213-
# PowerShell 7 catch System.Net.Http.Headers.HttpResponseHeaders
214-
# Contains/GetValues work. The string indexer
215-
# returns EMPTY instead of throwing, so it must
216-
# not be tried first.
217-
# Windows PowerShell 5.1 System.Net.WebHeaderCollection, which has a
218-
# string indexer and no Contains method.
219-
# success path a Dictionary, so ContainsKey.
210+
# Reads X-Cs-Region off a response whose header collection type differs by
211+
# platform and by which code path produced it, and where the wrong accessor
212+
# fails quietly rather than loudly. Measured:
213+
# PowerShell 7, thrown 3xx System.Net.Http.Headers.HttpResponseHeaders.
214+
# Contains/GetValues work, but the string
215+
# indexer returns EMPTY rather than failing,
216+
# so it must not be tried first.
217+
# Windows PowerShell 5.1, Invoke-WebRequest RETURNS the 3xx as a
218+
# returned 3xx WebResponseObject; this reads the region off
219+
# it correctly end to end. Its Content is a
220+
# Byte[], which is what made the old code fail
221+
# in ConvertFrom-Json before ever getting here.
222+
# 5.1, thrown errors System.Net.WebHeaderCollection, which has a
223+
# string indexer and no Contains method. The
224+
# indexer branch below is verified against a
225+
# real one on 5.1.
226+
# Hence: probe by type and by which accessor exists, rather than assuming.
220227
if (!$Response) {
221228
return $null
222229
}

powershell/install/falcon_windows_uninstall.ps1

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,23 @@ begin {
193193
}
194194

195195
function Get-FalconRegionHeader($Response) {
196-
# Reads X-Cs-Region off a response whose header collection type varies by
197-
# platform and by which code path produced it. The wrong accessor fails
198-
# quietly rather than loudly, so probe instead of assuming. Measured:
199-
# PowerShell 7 catch System.Net.Http.Headers.HttpResponseHeaders
200-
# Contains/GetValues work. The string indexer
201-
# returns EMPTY instead of throwing, so it must
202-
# not be tried first.
203-
# Windows PowerShell 5.1 System.Net.WebHeaderCollection, which has a
204-
# string indexer and no Contains method.
205-
# success path a Dictionary, so ContainsKey.
196+
# Reads X-Cs-Region off a response whose header collection type differs by
197+
# platform and by which code path produced it, and where the wrong accessor
198+
# fails quietly rather than loudly. Measured:
199+
# PowerShell 7, thrown 3xx System.Net.Http.Headers.HttpResponseHeaders.
200+
# Contains/GetValues work, but the string
201+
# indexer returns EMPTY rather than failing,
202+
# so it must not be tried first.
203+
# Windows PowerShell 5.1, Invoke-WebRequest RETURNS the 3xx as a
204+
# returned 3xx WebResponseObject; this reads the region off
205+
# it correctly end to end. Its Content is a
206+
# Byte[], which is what made the old code fail
207+
# in ConvertFrom-Json before ever getting here.
208+
# 5.1, thrown errors System.Net.WebHeaderCollection, which has a
209+
# string indexer and no Contains method. The
210+
# indexer branch below is verified against a
211+
# real one on 5.1.
212+
# Hence: probe by type and by which accessor exists, rather than assuming.
206213
if (!$Response) {
207214
return $null
208215
}

powershell/migrate/falcon_windows_migrate.ps1

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,16 +1004,23 @@ function Get-FalconCloud ([string] $xCsRegion) {
10041004

10051005

10061006
function Get-FalconRegionHeader($Response) {
1007-
# Reads X-Cs-Region off a response whose header collection type varies by
1008-
# platform and by which code path produced it. The wrong accessor fails
1009-
# quietly rather than loudly, so probe instead of assuming. Measured:
1010-
# PowerShell 7 catch System.Net.Http.Headers.HttpResponseHeaders
1011-
# Contains/GetValues work. The string indexer
1012-
# returns EMPTY instead of throwing, so it must
1013-
# not be tried first.
1014-
# Windows PowerShell 5.1 System.Net.WebHeaderCollection, which has a
1015-
# string indexer and no Contains method.
1016-
# success path a Dictionary, so ContainsKey.
1007+
# Reads X-Cs-Region off a response whose header collection type differs by
1008+
# platform and by which code path produced it, and where the wrong accessor
1009+
# fails quietly rather than loudly. Measured:
1010+
# PowerShell 7, thrown 3xx System.Net.Http.Headers.HttpResponseHeaders.
1011+
# Contains/GetValues work, but the string indexer
1012+
# returns EMPTY rather than failing, so it must
1013+
# not be tried first.
1014+
# Windows PowerShell 5.1, Invoke-WebRequest RETURNS the 3xx as a
1015+
# returned 3xx WebResponseObject; this reads the region off it
1016+
# correctly end to end. Its Content is a Byte[],
1017+
# which is what made the old code fail in
1018+
# ConvertFrom-Json before ever getting here.
1019+
# 5.1, thrown errors System.Net.WebHeaderCollection, which has a
1020+
# string indexer and no Contains method. The
1021+
# indexer branch below is verified against a real
1022+
# one on 5.1.
1023+
# Hence: probe by type and by which accessor exists, rather than assuming.
10171024
if (!$Response) {
10181025
return $null
10191026
}

0 commit comments

Comments
 (0)