Skip to content

Commit 5c76bfa

Browse files
Merge branch 'main' into js/taghelper
2 parents 05fd0e5 + 135c8b1 commit 5c76bfa

File tree

7 files changed

+46
-56
lines changed

7 files changed

+46
-56
lines changed

src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCache.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using Azure;
65
using Azure.Storage.Blobs;
@@ -31,7 +30,7 @@ public AzureBlobStorageCache(IOptions<AzureBlobStorageCacheOptions> cacheOptions
3130
}
3231

3332
/// <inheritdoc/>
34-
public async Task<IImageCacheResolver> GetAsync(string key)
33+
public async Task<IImageCacheResolver?> GetAsync(string key)
3534
{
3635
BlobClient blob = this.container.GetBlobClient(key);
3736

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
namespace SixLabors.ImageSharp.Web.Caching.Azure;
65

76
/// <summary>
87
/// Configuration options for the <see cref="AzureBlobStorageCache"/>.
98
/// </summary>
10-
public class AzureBlobStorageCacheOptions : IAzureBlobContainerClientOptions
9+
public class AzureBlobStorageCacheOptions
1110
{
12-
/// <inheritdoc/>
13-
public string ConnectionString { get; set; }
11+
/// <summary>
12+
/// Gets or sets the Azure Blob Storage connection string.
13+
/// <see href="https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string."/>
14+
/// </summary>
15+
public string ConnectionString { get; set; } = null!;
1416

15-
/// <inheritdoc/>
16-
public string ContainerName { get; set; }
17+
/// <summary>
18+
/// Gets or sets the Azure Blob Storage container name.
19+
/// Must conform to Azure Blob Storage container naming guidlines.
20+
/// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names"/>
21+
/// </summary>
22+
public string ContainerName { get; set; } = null!;
1723
}

src/ImageSharp.Web.Providers.Azure/IAzureBlobContainerClientOptions.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProvider.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using Azure.Storage.Blobs;
65
using Microsoft.AspNetCore.Http;
@@ -27,11 +26,6 @@ public class AzureBlobStorageImageProvider : IImageProvider
2726
private readonly Dictionary<string, BlobContainerClient> containers
2827
= new();
2928

30-
/// <summary>
31-
/// The blob storage options.
32-
/// </summary>
33-
private readonly AzureBlobStorageImageProviderOptions storageOptions;
34-
3529
/// <summary>
3630
/// Contains various helper methods based on the current configuration.
3731
/// </summary>
@@ -40,7 +34,7 @@ private readonly Dictionary<string, BlobContainerClient> containers
4034
/// <summary>
4135
/// A match function used by the resolver to identify itself as the correct resolver to use.
4236
/// </summary>
43-
private Func<HttpContext, bool> match;
37+
private Func<HttpContext, bool>? match;
4438

4539
/// <summary>
4640
/// Initializes a new instance of the <see cref="AzureBlobStorageImageProvider"/> class.
@@ -53,13 +47,12 @@ public AzureBlobStorageImageProvider(
5347
{
5448
Guard.NotNull(storageOptions, nameof(storageOptions));
5549

56-
this.storageOptions = storageOptions.Value;
5750
this.formatUtilities = formatUtilities;
5851

59-
foreach (AzureBlobContainerClientOptions container in this.storageOptions.BlobContainers)
52+
foreach (AzureBlobContainerClientOptions container in storageOptions.Value.BlobContainers)
6053
{
6154
this.containers.Add(
62-
container.ContainerName,
55+
container.ContainerName!,
6356
new BlobContainerClient(container.ConnectionString, container.ContainerName));
6457
}
6558
}
@@ -75,19 +68,25 @@ public Func<HttpContext, bool> Match
7568
}
7669

7770
/// <inheritdoc/>
78-
public async Task<IImageResolver> GetAsync(HttpContext context)
71+
public async Task<IImageResolver?> GetAsync(HttpContext context)
7972
{
8073
// Strip the leading slash and container name from the HTTP request path and treat
8174
// the remaining path string as the blob name.
8275
// Path has already been correctly parsed before here.
8376
string containerName = string.Empty;
84-
BlobContainerClient container = null;
77+
BlobContainerClient? container = null;
8578

8679
// We want an exact match here to ensure that container names starting with
8780
// the same prefix are not mixed up.
88-
string path = context.Request.Path.Value.TrimStart(SlashChars);
81+
string? path = context.Request.Path.Value?.TrimStart(SlashChars);
82+
83+
if (path is null)
84+
{
85+
return null;
86+
}
87+
8988
int index = path.IndexOfAny(SlashChars);
90-
string nameToMatch = index != -1 ? path.Substring(0, index) : path;
89+
string nameToMatch = index != -1 ? path[..index] : path;
9190

9291
foreach (string key in this.containers.Keys)
9392
{
@@ -131,7 +130,13 @@ private bool IsMatch(HttpContext context)
131130
{
132131
// Only match loosly here for performance.
133132
// Path matching conflicts should be dealt with by configuration.
134-
string path = context.Request.Path.Value.TrimStart(SlashChars);
133+
string? path = context.Request.Path.Value?.TrimStart(SlashChars);
134+
135+
if (path is null)
136+
{
137+
return false;
138+
}
139+
135140
foreach (string container in this.containers.Keys)
136141
{
137142
if (path.StartsWith(container, StringComparison.OrdinalIgnoreCase))

src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProviderOptions.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
namespace SixLabors.ImageSharp.Web.Providers.Azure;
65

@@ -18,11 +17,18 @@ public class AzureBlobStorageImageProviderOptions
1817
/// <summary>
1918
/// Represents a single Azure Blob Storage connection and container.
2019
/// </summary>
21-
public class AzureBlobContainerClientOptions : IAzureBlobContainerClientOptions
20+
public class AzureBlobContainerClientOptions
2221
{
23-
/// <inheritdoc/>
24-
public string ConnectionString { get; set; }
22+
/// <summary>
23+
/// Gets or sets the Azure Blob Storage connection string.
24+
/// <see href="https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string."/>
25+
/// </summary>
26+
public string? ConnectionString { get; set; }
2527

26-
/// <inheritdoc/>
27-
public string ContainerName { get; set; }
28+
/// <summary>
29+
/// Gets or sets the Azure Blob Storage container name.
30+
/// Must conform to Azure Blob Storage container naming guidlines.
31+
/// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names"/>
32+
/// </summary>
33+
public string? ContainerName { get; set; }
2834
}

src/ImageSharp.Web.Providers.Azure/Resolvers/AzureBlobStorageCacheResolver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using Azure.Storage.Blobs;
65
using Azure.Storage.Blobs.Models;

src/ImageSharp.Web.Providers.Azure/Resolvers/AzureBlobStorageImageResolver.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Net.Http.Headers;
65
using Azure.Storage.Blobs;
@@ -32,7 +31,7 @@ public async Task<ImageMetadata> GetMetaDataAsync()
3231
// Try to parse the max age from the source. If it's not zero then we pass it along
3332
// to set the cache control headers for the response.
3433
TimeSpan maxAge = TimeSpan.MinValue;
35-
if (CacheControlHeaderValue.TryParse(properties.CacheControl, out CacheControlHeaderValue cacheControl))
34+
if (CacheControlHeaderValue.TryParse(properties.CacheControl, out CacheControlHeaderValue? cacheControl))
3635
{
3736
// Weirdly passing null to TryParse returns true.
3837
if (cacheControl?.MaxAge.HasValue == true)

0 commit comments

Comments
 (0)