Skip to content

Commit ea53ceb

Browse files
Refactor to recommended header usage
1 parent 343e658 commit ea53ceb

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/AspNetCore/WebApi/src/Asp.Versioning.Http/DefaultApiVersionReporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private static void AddApiVersionHeader( IHeaderDictionary headers, string heade
2121

2222
if ( versions.Count == 1 )
2323
{
24-
headers.Add( headerName, versions[0].ToString() );
24+
headers[headerName] = versions[0].ToString();
2525
return;
2626
}
2727

@@ -55,7 +55,7 @@ private static void AddApiVersionHeader( IHeaderDictionary headers, string heade
5555
}
5656
}
5757

58-
headers.Add( headerName, headerValue.ToString() );
58+
headers[headerName] = headerValue.ToString();
5959
pool.Return( array );
6060
}
6161
}

src/AspNetCore/WebApi/src/Asp.Versioning.Http/Http/HttpResponseExtensions.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void WriteSunsetPolicy( this HttpResponse response, SunsetPolicy s
3838

3939
if ( sunsetPolicy.Date.HasValue )
4040
{
41-
headers.Add( Sunset, sunsetPolicy.Date.Value.ToString( "r" ) );
41+
headers[Sunset] = sunsetPolicy.Date.Value.ToString( "r" );
4242
}
4343

4444
AddLinkHeaders( headers, sunsetPolicy.Links );
@@ -53,16 +53,7 @@ private static void AddLinkHeaders( IHeaderDictionary headers, IList<LinkHeaderV
5353
values[i] = links[i].ToString();
5454
}
5555

56-
var newValues = new StringValues( values );
57-
58-
if ( headers.TryGetValue( Link, out var existingValues ) )
59-
{
60-
headers[Link] = StringValues.Concat( existingValues, newValues );
61-
}
62-
else
63-
{
64-
headers.Add( Link, newValues );
65-
}
56+
headers.Append( Link, values );
6657
}
6758

6859
/// <summary>

0 commit comments

Comments
 (0)