Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename IIIF-CS-Show-Extra header #13

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class HttpRequestMessageBuilder
public static HttpRequestMessage GetPrivateRequest(HttpMethod method, string path, string content)
{
var requestMessage = new HttpRequestMessage(method, path);
requestMessage.Headers.Add("IIIF-CS-Show-Extra", "All");
requestMessage.Headers.Add("X-IIIF-CS-Show-Extras", "All");
requestMessage.Content = new StringContent(content, Encoding.UTF8, "application/json");

return requestMessage;
Expand All @@ -16,7 +16,7 @@ public static HttpRequestMessage GetPrivateRequest(HttpMethod method, string pat
public static HttpRequestMessage GetPrivateRequest(HttpMethod method, string path)
{
var requestMessage = new HttpRequestMessage(method, path);
requestMessage.Headers.Add("IIIF-CS-Show-Extra", "All");
requestMessage.Headers.Add("X-IIIF-CS-Show-Extras", "All");

return requestMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public async Task CreateCollection_FailsToCreateCollection_WhenCalledWithIncorre
};

var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"{Customer}/collections");
requestMessage.Headers.Add("IIIF-CS-Show-Extra", "Incorrect");
requestMessage.Headers.Add("X-IIIF-CS-Show-Extras", "Incorrect");
requestMessage.Content = new StringContent(JsonSerializer.Serialize(collection), Encoding.UTF8,
new MediaTypeHeaderValue("application/json"));

Expand Down
6 changes: 4 additions & 2 deletions src/IIIFPresentation/API/Attributes/EtagCachingAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Security.Cryptography;
using API.Infrastructure.Helpers;
using Microsoft.AspNetCore.Http.Headers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
Expand Down Expand Up @@ -42,12 +43,11 @@ ResultExecutionDelegate next

if (response.StatusCode == StatusCodes.Status200OK)
{
var requestHeaders = request.GetTypedHeaders();
var responseHeaders = response.GetTypedHeaders();

responseHeaders.CacheControl = new CacheControlHeaderValue() // how long clients should cache the response
{
Public = !requestHeaders.Headers.Keys.Contains("IIIF-CS-Show-Extra"),
Public = request.HasShowExtraHeader(),
MaxAge = TimeSpan.FromDays(365)
};

Expand All @@ -57,6 +57,8 @@ ResultExecutionDelegate next
GenerateETag(memoryStream,
request.Path); // This request generates a hash from the response - this would come from S3 in live
}

var requestHeaders = request.GetTypedHeaders();

if (IsClientCacheValid(requestHeaders, responseHeaders))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ namespace API.Infrastructure.Helpers;

public static class HttpRequestX
{
private static readonly KeyValuePair<string, string> AdditionalPropertiesHeader = new KeyValuePair<string, string>("IIIF-CS-Show-Extra", "All");
private static readonly KeyValuePair<string, string> AdditionalPropertiesHeader = new ("X-IIIF-CS-Show-Extras", "All");

public static bool ShowExtraProperties(this HttpRequest request)
{
return request.Headers.FirstOrDefault(x => x.Key == AdditionalPropertiesHeader.Key).Value == AdditionalPropertiesHeader.Value &&
Authorizer.CheckAuthorized(request);
}

public static bool HasShowExtraHeader(this HttpRequest request)
{
return request.Headers.FirstOrDefault(x => x.Key == AdditionalPropertiesHeader.Key).Value ==
AdditionalPropertiesHeader.Value;
}
}
Loading