Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 2dfa0ab

Browse files
documentation is in english and text/markdown
also specify application/hal+json for everything else
1 parent bfc6508 commit 2dfa0ab

7 files changed

Lines changed: 23 additions & 17 deletions

File tree

src/SqlStreamStore.HAL.Tests/StreamAppendTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public async Task wrong_expected_version(int[] expectedVersions)
186186
{
187187
response.StatusCode.ShouldBe(HttpStatusCode.Conflict);
188188
response.Content.Headers.ContentType.ShouldBe(new MediaTypeHeaderValue(
189-
Constants.Headers.ContentTypes.HalJson));
189+
Constants.MediaTypes.HalJson));
190190
}
191191
var page = await _fixture.StreamStore.ReadStreamForwards(StreamId, 0, int.MaxValue);
192192

@@ -250,7 +250,7 @@ public async Task malformed_request_body(string malformedRequest)
250250
{
251251
Content = new StringContent(malformedRequest)
252252
{
253-
Headers = { ContentType = new MediaTypeHeaderValue(Constants.Headers.ContentTypes.HalJson) }
253+
Headers = { ContentType = new MediaTypeHeaderValue(Constants.MediaTypes.HalJson) }
254254
}
255255
}))
256256
{

src/SqlStreamStore.HAL.Tests/StreamDeleteTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task wrong_expected_version(int expectedVersion)
5757
{
5858
response.StatusCode.ShouldBe(HttpStatusCode.Conflict);
5959
response.Content.Headers.ContentType.ShouldBe(new MediaTypeHeaderValue(
60-
Constants.Headers.ContentTypes.HalJson));
60+
Constants.MediaTypes.HalJson));
6161
}
6262

6363
var page = await _fixture.StreamStore.ReadStreamForwards(StreamId, 0, 1);

src/SqlStreamStore.HAL.Tests/StreamMetadataTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public async Task set_wrong_expected_version(int[] expectedVersions)
214214
{
215215
response.StatusCode.ShouldBe(HttpStatusCode.Conflict);
216216
response.Content.Headers.ContentType.ShouldBe(new MediaTypeHeaderValue(
217-
Constants.Headers.ContentTypes.HalJson));
217+
Constants.MediaTypes.HalJson));
218218
}
219219

220220
var page = await _fixture.StreamStore.ReadStreamForwards($"$${StreamId}", 0, int.MaxValue);

src/SqlStreamStore.HAL/Constants.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ namespace SqlStreamStore.HAL
22
{
33
internal static class Constants
44
{
5+
public static class MediaTypes
6+
{
7+
public const string TextMarkdown = "text/markdown; charset=UTF-8";
8+
public const string HalJson = "application/hal+json";
9+
public const string Any = "*/*";
10+
}
11+
512
public static class Headers
613
{
714
public const string ExpectedVersion = "SSS-ExpectedVersion";
@@ -11,13 +18,6 @@ public static class Headers
1118
public const string ETag = "ETag";
1219
public const string IfNoneMatch = "If-None-Match";
1320
public const string CacheControl = "Cache-Control";
14-
15-
public static class ContentTypes
16-
{
17-
public const string Json = "application/json";
18-
public const string HalJson = "application/hal+json";
19-
public const string Any = "*/*";
20-
}
2121
}
2222

2323
public static class Relations

src/SqlStreamStore.HAL/HttpContextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private static async Task WriteHalResponse(HttpContext context, Response respons
7070
{
7171
context.Response.StatusCode = response.StatusCode;
7272

73-
context.Response.ContentType = Constants.Headers.ContentTypes.HalJson;
73+
context.Response.ContentType = Constants.MediaTypes.HalJson;
7474

7575
foreach(var header in response.Headers)
7676
{

src/SqlStreamStore.HAL/Links.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,21 @@ public Link[] ToHalLinks()
6363
var (rel, href, title) = _links[i];
6464
var resolvedHref = $"{_relativePathToRoot}{href}";
6565

66-
links[i] = new Link(rel, resolvedHref, title, replaceParameters: false);
66+
links[i] = new Link(rel, resolvedHref, title, replaceParameters: false)
67+
{
68+
Type = Constants.MediaTypes.HalJson
69+
};
6770
}
6871

6972
links[_links.Count] = new Link(
7073
Constants.Relations.Curies,
7174
$"{_relativePathToRoot}docs/{{rel}}",
75+
"Documentation",
7276
replaceParameters: false)
7377
{
74-
Name = Constants.Relations.StreamStorePrefix
78+
Name = Constants.Relations.StreamStorePrefix,
79+
HrefLang = "en",
80+
Type = Constants.MediaTypes.TextMarkdown
7581
};
7682

7783
return links;

src/SqlStreamStore.HAL/SqlStreamStoreHalMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public static class SqlStreamStoreHalMiddleware
4141
{
4242
var accept = context.Request.GetAcceptHeaders();
4343

44-
return accept.Any(header => header == Constants.Headers.ContentTypes.HalJson
45-
|| header == Constants.Headers.ContentTypes.Any)
44+
return accept.Any(header => header == Constants.MediaTypes.HalJson
45+
|| header == Constants.MediaTypes.Any)
4646
? next()
4747
: context.WriteResponse(new Response(new HALResponse(new
4848
{
4949
type = "Not Acceptable",
5050
title = "Not Acceptable",
51-
detail = $"The server only understands {Constants.Headers.ContentTypes.HalJson}."
51+
detail = $"The server only understands {Constants.MediaTypes.HalJson}."
5252
}),
5353
406));
5454
};

0 commit comments

Comments
 (0)