From af662ecdef30f7255f8fa511a9377f88d0f68350 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Fri, 29 Mar 2024 11:12:26 +1100 Subject: [PATCH] Tweaks based on analyzers Signed-off-by: James Thompson --- .../HttpRequestExtensions.cs | 7 ++++--- .../HttpResponseExtensions.cs | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/CloudNative.CloudEvents.AspNetCore/HttpRequestExtensions.cs b/src/CloudNative.CloudEvents.AspNetCore/HttpRequestExtensions.cs index 1889243..555cd75 100644 --- a/src/CloudNative.CloudEvents.AspNetCore/HttpRequestExtensions.cs +++ b/src/CloudNative.CloudEvents.AspNetCore/HttpRequestExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Cloud Native Foundation. +// Copyright (c) Cloud Native Foundation. // Licensed under the Apache 2.0 license. // See LICENSE file in the project root for full license information. @@ -94,11 +94,12 @@ namespace CloudNative.CloudEvents.AspNetCore foreach (var header in headers) { string? attributeName = HttpUtilities.GetAttributeNameFromHeaderName(header.Key); - if (attributeName is null || attributeName == CloudEventsSpecVersion.SpecVersionAttribute.Name) + string? headerValue = header.Value.First(); + if (attributeName is null || attributeName == CloudEventsSpecVersion.SpecVersionAttribute.Name || headerValue is null) { continue; } - string attributeValue = HttpUtilities.DecodeHeaderValue(header.Value.First()); + string attributeValue = HttpUtilities.DecodeHeaderValue(headerValue); cloudEvent.SetAttributeFromString(attributeName, attributeValue); } diff --git a/src/CloudNative.CloudEvents.AspNetCore/HttpResponseExtensions.cs b/src/CloudNative.CloudEvents.AspNetCore/HttpResponseExtensions.cs index 102a871..482d741 100644 --- a/src/CloudNative.CloudEvents.AspNetCore/HttpResponseExtensions.cs +++ b/src/CloudNative.CloudEvents.AspNetCore/HttpResponseExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Cloud Native Foundation. +// Copyright (c) Cloud Native Foundation. // Licensed under the Apache 2.0 license. // See LICENSE file in the project root for full license information. @@ -57,8 +57,8 @@ namespace CloudNative.CloudEvents.AspNetCore // Map headers in either mode. // Including the headers in structured mode is optional in the spec (as they're already within the body) but - // can be useful. - destination.Headers.Add(HttpUtilities.SpecVersionHttpHeader, HttpUtilities.EncodeHeaderValue(cloudEvent.SpecVersion.VersionId)); + // can be useful. + destination.Headers.Append(HttpUtilities.SpecVersionHttpHeader, HttpUtilities.EncodeHeaderValue(cloudEvent.SpecVersion.VersionId)); foreach (var attributeAndValue in cloudEvent.GetPopulatedAttributes()) { var attribute = attributeAndValue.Key; @@ -67,7 +67,7 @@ namespace CloudNative.CloudEvents.AspNetCore if (attribute != cloudEvent.SpecVersion.DataContentTypeAttribute) { string headerValue = HttpUtilities.EncodeHeaderValue(attribute.Format(value)); - destination.Headers.Add(HttpUtilities.HttpHeaderPrefix + attribute.Name, headerValue); + destination.Headers.Append(HttpUtilities.HttpHeaderPrefix + attribute.Name, headerValue); } }