Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit 25c3f7f

Browse files
committed
- aligns on the abstractions header type
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent eb8f45f commit 25c3f7f

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/HeadersInspectionHandlerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.Threading.Tasks;
56
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
@@ -33,7 +34,7 @@ public async Task HeadersInspectionHandlerGetsRequestHeaders()
3334
var response = await invoker.SendAsync(request, default);
3435

3536
// Then
36-
Assert.Equal("test", option.RequestHeaders["test"]);
37+
Assert.Equal("test", option.RequestHeaders["test"].First());
3738
Assert.Empty(option.ResponseHeaders);
3839
}
3940
[Fact]
@@ -50,7 +51,7 @@ public async Task HeadersInspectionHandlerGetsResponseHeaders()
5051
var response = await invoker.SendAsync(request, default);
5152

5253
// Then
53-
Assert.Equal("test", option.ResponseHeaders["test"]);
54+
Assert.Equal("test", option.ResponseHeaders["test"].First());
5455
Assert.Empty(option.RequestHeaders);
5556
}
5657
private HttpMessageInvoker GetMessageInvoker(HeadersInspectionHandlerOption option = null)

src/Middleware/HeadersInspectionHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Diagnostics;
7+
using System.Linq;
78
using System.Net.Http;
89
using System.Threading;
910
using System.Threading.Tasks;
@@ -52,15 +53,15 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
5253
{
5354
foreach(var header in request.Headers)
5455
{
55-
options.RequestHeaders[header.Key] = string.Join(",", header.Value);
56+
options.RequestHeaders[header.Key] = header.Value.ToArray();
5657
}
5758
}
5859
var response = await base.SendAsync(request, cancellationToken);
5960
if(options.InspectResponseHeaders)
6061
{
6162
foreach(var header in response.Headers)
6263
{
63-
options.ResponseHeaders[header.Key] = string.Join(",", header.Value);
64+
options.ResponseHeaders[header.Key] = header.Value.ToArray();
6465
}
6566
}
6667
return response;

src/Middleware/Options/HeadersInspectionHandlerOption.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@
22
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33
// ------------------------------------------------------------------------------
44

5-
using System;
6-
using System.Collections.Generic;
75
using Microsoft.Kiota.Abstractions;
86

97
namespace Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options;
108
/// <summary>
119
/// The Headers Inspection Option allows the developer to inspect the headers of the request and response.
1210
/// </summary>
13-
public class HeadersInspectionHandlerOption: IRequestOption
11+
public class HeadersInspectionHandlerOption : IRequestOption
1412
{
1513
/// <summary>
1614
/// Gets or sets a value indicating whether the request headers should be inspected.
1715
/// </summary>
18-
public bool InspectRequestHeaders { get; set; }
16+
public bool InspectRequestHeaders
17+
{
18+
get; set;
19+
}
1920
/// <summary>
2021
/// Gets or sets a value indicating whether the response headers should be inspected.
2122
/// </summary>
22-
public bool InspectResponseHeaders { get; set; }
23+
public bool InspectResponseHeaders
24+
{
25+
get; set;
26+
}
2327
/// <summary>
2428
/// Gets the request headers to for the current request.
2529
/// </summary>
26-
public IDictionary<string, string> RequestHeaders { get; private set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
30+
public RequestHeaders RequestHeaders { get; private set; } = new RequestHeaders();
2731
/// <summary>
2832
/// Gets the response headers for the current request.
2933
/// </summary>
30-
public IDictionary<string, string> ResponseHeaders { get; private set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
34+
public RequestHeaders ResponseHeaders { get; private set; } = new RequestHeaders();
3135
}

0 commit comments

Comments
 (0)