Skip to content

Commit c3e5a16

Browse files
committed
More tests
1 parent 87e30a6 commit c3e5a16

19 files changed

+649
-57
lines changed

src/StaticWebAssetsSdk/Tasks/ApplyCompressionNegotiation.cs

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

66
using System.Globalization;
77
using Microsoft.Build.Framework;
8-
using Microsoft.NET.Sdk.StaticWebAssets.Tasks.Utils;
8+
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
99

1010
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
1111

src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpointProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Diagnostics;
88
using System.Text.Json;
99
using System.Text.Json.Serialization.Metadata;
10-
using Microsoft.NET.Sdk.StaticWebAssets.Tasks.Utils;
10+
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
1111

1212
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
1313

src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpointResponseHeader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Diagnostics;
88
using System.Text.Json;
99
using System.Text.Json.Serialization.Metadata;
10-
using Microsoft.NET.Sdk.StaticWebAssets.Tasks.Utils;
10+
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
1111

1212
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
1313

src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpointSelector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Diagnostics;
88
using System.Text.Json;
99
using System.Text.Json.Serialization.Metadata;
10-
using Microsoft.NET.Sdk.StaticWebAssets.Tasks.Utils;
10+
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
1111

1212
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
1313

src/StaticWebAssetsSdk/Tasks/Data/WellKnownEndpointSelectorNames.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#nullable disable
5+
46
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
57

68
internal static class WellKnownEndpointSelectorNames
@@ -20,6 +22,6 @@ public static string TryGetInternedSelectorName(ReadOnlySpan<byte> selectorNameS
2022
{
2123
16 => selectorNameSpan.SequenceEqual("Content-Encoding"u8) ? ContentEncoding : null,
2224
_ => null
23-
})!;
25+
});
2426
}
2527
}

src/StaticWebAssetsSdk/Tasks/Data/WellKnownEndpointSelectorValues.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#nullable disable
5+
46
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
57

68
internal static class WellKnownEndpointSelectorValues
@@ -22,6 +24,6 @@ public static string TryGetInternedSelectorValue(ReadOnlySpan<byte> selectorValu
2224
2 => selectorValueSpan.SequenceEqual("br"u8) ? Brotli : null,
2325
4 => selectorValueSpan.SequenceEqual("gzip"u8) ? Gzip : null,
2426
_ => null
25-
})!;
27+
});
2628
}
2729
}

src/StaticWebAssetsSdk/Tasks/Data/WellKnownResponseHeaderValues.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ public static string TryGetInternedHeaderValue(ReadOnlySpan<byte> headerValueSpa
4343
2 => headerValueSpan.SequenceEqual("br"u8) ? Brotli : null,
4444
4 => headerValueSpan.SequenceEqual("gzip"u8) ? Gzip : null,
4545
5 => headerValueSpan.SequenceEqual("bytes"u8) ? Bytes : null,
46-
8 => headerValueSpan.SequenceEqual("no-cache"u8) ? NoCache : null,
47-
9 => headerValueSpan[0] switch
46+
8 => headerValueSpan[0] switch
4847
{
48+
(byte)'n' when headerValueSpan.SequenceEqual("no-cache"u8) => NoCache,
4949
(byte)'t' when headerValueSpan.SequenceEqual("text/css"u8) => TextCss,
50+
_ => null
51+
},
52+
9 => headerValueSpan[0] switch
53+
{
5054
(byte)'t' when headerValueSpan.SequenceEqual("text/html"u8) => TextHtml,
5155
(byte)'i' when headerValueSpan.SequenceEqual("image/png"u8) => ImagePng,
5256
_ => null
@@ -61,7 +65,7 @@ public static string TryGetInternedHeaderValue(ReadOnlySpan<byte> headerValueSpa
6165
_ => null
6266
},
6367
24 => headerValueSpan.SequenceEqual("application/octet-stream"u8) ? ApplicationOctetStream : null,
64-
29 => headerValueSpan.SequenceEqual("max-age=31536000, immutable"u8) ? MaxAgeImmutable : null,
68+
27 => headerValueSpan.SequenceEqual("max-age=31536000, immutable"u8) ? MaxAgeImmutable : null,
6569
_ => null
6670
};
6771
}

src/StaticWebAssetsSdk/Tasks/Data/WellKnownResponseHeaders.cs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,27 @@ internal static class WellKnownResponseHeaders
1717
public const string LastModified = "Last-Modified";
1818
public const string Vary = "Vary";
1919

20-
/// <summary>
21-
/// Gets the interned header name if it's a well-known header, otherwise returns the original string.
22-
/// Uses span comparison for efficiency.
23-
/// </summary>
24-
/// <param name="headerNameSpan">The header name span to check</param>
25-
/// <returns>The interned header name or null if not well-known</returns>
2620
public static string TryGetInternedHeaderName(ReadOnlySpan<byte> headerNameSpan)
2721
{
28-
// Check each well-known header using UTF-8 span comparison
29-
if (headerNameSpan.SequenceEqual("Accept-Ranges"u8))
30-
{
31-
return AcceptRanges;
32-
}
33-
if (headerNameSpan.SequenceEqual("Cache-Control"u8))
34-
{
35-
return CacheControl;
36-
}
37-
if (headerNameSpan.SequenceEqual("Content-Encoding"u8))
38-
{
39-
return ContentEncoding;
40-
}
41-
if (headerNameSpan.SequenceEqual("Content-Length"u8))
42-
{
43-
return ContentLength;
44-
}
45-
if (headerNameSpan.SequenceEqual("Content-Type"u8))
46-
{
47-
return ContentType;
48-
}
49-
if (headerNameSpan.SequenceEqual("ETag"u8))
50-
{
51-
return ETag;
52-
}
53-
if (headerNameSpan.SequenceEqual("Last-Modified"u8))
54-
{
55-
return LastModified;
56-
}
57-
if (headerNameSpan.SequenceEqual("Vary"u8))
58-
{
59-
return Vary;
60-
}
61-
62-
return null;
22+
return headerNameSpan.Length switch
23+
{
24+
4 => headerNameSpan[0] switch
25+
{
26+
(byte)'E' when headerNameSpan.SequenceEqual("ETag"u8) => ETag,
27+
(byte)'V' when headerNameSpan.SequenceEqual("Vary"u8) => Vary,
28+
_ => null
29+
},
30+
12 => headerNameSpan.SequenceEqual("Content-Type"u8) ? ContentType : null,
31+
13 => headerNameSpan[0] switch
32+
{
33+
(byte)'A' when headerNameSpan.SequenceEqual("Accept-Ranges"u8) => AcceptRanges,
34+
(byte)'C' when headerNameSpan.SequenceEqual("Cache-Control"u8) => CacheControl,
35+
(byte)'L' when headerNameSpan.SequenceEqual("Last-Modified"u8) => LastModified,
36+
_ => null
37+
},
38+
14 => headerNameSpan.SequenceEqual("Content-Length"u8) ? ContentLength : null,
39+
16 => headerNameSpan.SequenceEqual("Content-Encoding"u8) ? ContentEncoding : null,
40+
_ => null
41+
};
6342
}
6443
}

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#nullable disable
55
using Microsoft.Build.Framework;
6-
using Microsoft.NET.Sdk.StaticWebAssets.Tasks.Utils;
76
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
87
using Microsoft.Build.Utilities;
98

src/StaticWebAssetsSdk/Tasks/UpdateStaticWebAssetEndpoints.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#nullable disable
55

66
using Microsoft.Build.Framework;
7-
using Microsoft.NET.Sdk.StaticWebAssets.Tasks.Utils;
7+
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
88

99
namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
1010

0 commit comments

Comments
 (0)