Skip to content

Commit c3ce5dd

Browse files
authored
fix: parsing HTTP headers with duplicated name (#426)
1 parent 2c398b5 commit c3ce5dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+493
-474
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
### Features
88
1. [#388](https://github.com/influxdata/influxdb-client-csharp/pull/388): Initialize C# client without `InfluxDBClientFactory`
99

10+
### Bug Fixes
11+
1. [#426](https://github.com/influxdata/influxdb-client-csharp/pull/426): Parsing HTTP headers with duplicated name
12+
1013
### CI
1114
1. [#416](https://github.com/influxdata/influxdb-client-csharp/pull/416): Add build for `.NET 7.0`
1215

Client.Test/InfluxDbClientTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,19 @@ public async Task VersionIsNotCaseSensitive()
377377
Assert.AreEqual("2.0.0", await _client.VersionAsync());
378378
}
379379

380+
[Test]
381+
public void DuplicatedHeader()
382+
{
383+
MockServer.Given(Request.Create().WithPath("/ping").UsingGet())
384+
.RespondWith(Response.Create().WithStatusCode(204)
385+
.WithHeader("x-influxdb-version", "2.0.1")
386+
.WithHeader("x-influxdb-version", "2.0.0"));
387+
388+
var response = _client.CreateService<PingService>(typeof(PingService)).GetPingWithHttpInfo();
389+
390+
Assert.AreEqual("2.0.0", response.Headers["x-influxdb-version"]);
391+
}
392+
380393
[Test]
381394
public async Task CustomCertificateValidationCallback()
382395
{

Client/Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<ItemGroup>
3232
<None Include="..\Assets\influxdata.jpg" Pack="true" PackagePath="" />
33-
<None Include=".\README.md" Pack="true" PackagePath="\"/>
33+
<None Include=".\README.md" Pack="true" PackagePath="\" />
3434
<ProjectReference Include="..\Client.Core\Client.Core.csproj" />
3535
</ItemGroup>
3636

Client/InfluxDB.Client.Api/Client/ApiResponse.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* Generated by: https://github.com/openapitools/openapi-generator.git
99
*/
1010

11-
using System;
1211
using System.Collections.Generic;
12+
using System.Collections.Immutable;
13+
using System.Linq;
1314

1415
namespace InfluxDB.Client.Api.Client
1516
{
@@ -42,10 +43,12 @@ public class ApiResponse<T>
4243
/// <param name="statusCode">HTTP status code.</param>
4344
/// <param name="headers">HTTP headers.</param>
4445
/// <param name="data">Data (parsed HTTP body)</param>
45-
public ApiResponse(int statusCode, IDictionary<string, string> headers, T data)
46+
public ApiResponse(int statusCode, IEnumerable<(string Name, object Value)> headers, T data)
4647
{
4748
StatusCode = statusCode;
48-
Headers = headers;
49+
Headers = headers
50+
.GroupBy(h => h.Name)
51+
.ToDictionary(g => g.Key, g => g.FirstOrDefault().Value.ToString());
4952
Data = data;
5053
}
5154
}

Client/InfluxDB.Client.Api/Service/AuthorizationsService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public ApiResponse<object> DeleteAuthorizationsIDWithHttpInfo(string authID, str
507507
}
508508

509509
return new ApiResponse<object>(localVarStatusCode,
510-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
510+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
511511
null);
512512
}
513513

@@ -763,7 +763,7 @@ await DeleteAuthorizationsIDAsyncWithIRestResponse(authID, zapTraceSpan, cancell
763763
}
764764

765765
return new ApiResponse<object>(localVarStatusCode,
766-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
766+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
767767
null);
768768
}
769769

@@ -946,7 +946,7 @@ public ApiResponse<Authorizations> GetAuthorizationsWithHttpInfo(string zapTrace
946946
}
947947

948948
return new ApiResponse<Authorizations>(localVarStatusCode,
949-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
949+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
950950
(Authorizations)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorizations)));
951951
}
952952

@@ -1261,7 +1261,7 @@ await GetAuthorizationsAsyncWithIRestResponse(zapTraceSpan, userID, user, orgID,
12611261
}
12621262

12631263
return new ApiResponse<Authorizations>(localVarStatusCode,
1264-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
1264+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
12651265
(Authorizations)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorizations)));
12661266
}
12671267

@@ -1440,7 +1440,7 @@ public ApiResponse<Authorization> GetAuthorizationsIDWithHttpInfo(string authID,
14401440
}
14411441

14421442
return new ApiResponse<Authorization>(localVarStatusCode,
1443-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
1443+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
14441444
(Authorization)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorization)));
14451445
}
14461446

@@ -1698,7 +1698,7 @@ await GetAuthorizationsIDAsyncWithIRestResponse(authID, zapTraceSpan, cancellati
16981698
}
16991699

17001700
return new ApiResponse<Authorization>(localVarStatusCode,
1701-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
1701+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
17021702
(Authorization)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorization)));
17031703
}
17041704

@@ -1883,7 +1883,7 @@ public ApiResponse<Authorization> PatchAuthorizationsIDWithHttpInfo(string authI
18831883
}
18841884

18851885
return new ApiResponse<Authorization>(localVarStatusCode,
1886-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
1886+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
18871887
(Authorization)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorization)));
18881888
}
18891889

@@ -2206,7 +2206,7 @@ await PatchAuthorizationsIDAsyncWithIRestResponse(authID, authorizationUpdateReq
22062206
}
22072207

22082208
return new ApiResponse<Authorization>(localVarStatusCode,
2209-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
2209+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
22102210
(Authorization)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorization)));
22112211
}
22122212

@@ -2397,7 +2397,7 @@ public ApiResponse<Authorization> PostAuthorizationsWithHttpInfo(
23972397
}
23982398

23992399
return new ApiResponse<Authorization>(localVarStatusCode,
2400-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
2400+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
24012401
(Authorization)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorization)));
24022402
}
24032403

@@ -2679,7 +2679,7 @@ await PostAuthorizationsAsyncWithIRestResponse(authorizationPostRequest, zapTrac
26792679
}
26802680

26812681
return new ApiResponse<Authorization>(localVarStatusCode,
2682-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
2682+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
26832683
(Authorization)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Authorization)));
26842684
}
26852685

Client/InfluxDB.Client.Api/Service/BackupService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public System.IO.Stream GetBackupKV(string zapTraceSpan = null)
372372
}
373373

374374
return new ApiResponse<System.IO.Stream>(localVarStatusCode,
375-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
375+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
376376
(System.IO.Stream)Configuration.ApiClient.Deserialize(localVarResponse, typeof(System.IO.Stream)));
377377
}
378378

@@ -591,7 +591,7 @@ public RestRequest GetBackupKVWithRestRequest(string zapTraceSpan = null)
591591
}
592592

593593
return new ApiResponse<System.IO.Stream>(localVarStatusCode,
594-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
594+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
595595
(System.IO.Stream)Configuration.ApiClient.Deserialize(localVarResponse, typeof(System.IO.Stream)));
596596
}
597597

@@ -738,7 +738,7 @@ public ApiResponse<MetadataBackup> GetBackupMetadataWithHttpInfo(string zapTrace
738738
}
739739

740740
return new ApiResponse<MetadataBackup>(localVarStatusCode,
741-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
741+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
742742
(MetadataBackup)Configuration.ApiClient.Deserialize(localVarResponse, typeof(MetadataBackup)));
743743
}
744744

@@ -982,7 +982,7 @@ await GetBackupMetadataAsyncWithIRestResponse(zapTraceSpan, acceptEncoding, canc
982982
}
983983

984984
return new ApiResponse<MetadataBackup>(localVarStatusCode,
985-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
985+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
986986
(MetadataBackup)Configuration.ApiClient.Deserialize(localVarResponse, typeof(MetadataBackup)));
987987
}
988988

@@ -1159,7 +1159,7 @@ public System.IO.Stream GetBackupShardId(long? shardID, string zapTraceSpan = nu
11591159
}
11601160

11611161
return new ApiResponse<System.IO.Stream>(localVarStatusCode,
1162-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
1162+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
11631163
(System.IO.Stream)Configuration.ApiClient.Deserialize(localVarResponse, typeof(System.IO.Stream)));
11641164
}
11651165

@@ -1472,7 +1472,7 @@ await GetBackupShardIdAsyncWithIRestResponse(shardID, zapTraceSpan, acceptEncodi
14721472
}
14731473

14741474
return new ApiResponse<System.IO.Stream>(localVarStatusCode,
1475-
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
1475+
localVarResponse.Headers.Select(h => (h.Name, h.Value)),
14761476
(System.IO.Stream)Configuration.ApiClient.Deserialize(localVarResponse, typeof(System.IO.Stream)));
14771477
}
14781478

0 commit comments

Comments
 (0)