From a845ba4f4162d9853d2964434401f5855d869e7c Mon Sep 17 00:00:00 2001 From: Travis Prescott Date: Thu, 28 Mar 2024 14:45:49 -0700 Subject: [PATCH] Code review feedback. --- .../src/rules/lro-location-header.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/typespec-azure-resource-manager/src/rules/lro-location-header.ts b/packages/typespec-azure-resource-manager/src/rules/lro-location-header.ts index eac5743a9e..5289988e95 100644 --- a/packages/typespec-azure-resource-manager/src/rules/lro-location-header.ts +++ b/packages/typespec-azure-resource-manager/src/rules/lro-location-header.ts @@ -1,6 +1,21 @@ -import { Operation, createRule } from "@typespec/compiler"; +import { ModelProperty, Operation, createRule } from "@typespec/compiler"; import { getHttpOperation } from "@typespec/http"; +function getCaseInsensitiveHeader( + headers: Record | undefined, + key: string +): string | undefined { + if (!headers) { + return undefined; + } + for (const header of Object.keys(headers)) { + if (header.toLowerCase() === key.toLowerCase()) { + return header; + } + } + return undefined; +} + /** * Ensure that LRO 202 responses have a Location Header. */ @@ -22,7 +37,7 @@ export const lroLocationHeaderRule = createRule({ continue; } for (const resp of response.responses) { - if (resp.headers?.["Location"] === undefined) { + if (getCaseInsensitiveHeader(resp.headers, "Location") === undefined) { context.reportDiagnostic({ target: op, });