Skip to content

Commit 6c91c2e

Browse files
Yet more to be unifed
1 parent 1be1089 commit 6c91c2e

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

Modules/Placeholders/Providers/PageProvider.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ public sealed class PageProvider : IHandler
2424

2525
public PageAdditions? Additions { get; }
2626

27+
public ResponseModifications? Modifications { get; }
28+
2729
public IResource Content { get; }
2830

2931
#endregion
3032

3133
#region Initialization
3234

33-
public PageProvider(IHandler parent, ContentInfo pageInfo, PageAdditions? additions, IResource content)
35+
public PageProvider(IHandler parent, ContentInfo pageInfo, PageAdditions? additions, ResponseModifications? modifications, IResource content)
3436
{
3537
Parent = parent;
3638

3739
PageInfo = pageInfo;
3840
Additions = additions;
41+
Modifications = modifications;
3942

4043
Content = content;
4144
}
@@ -49,6 +52,8 @@ public PageProvider(IHandler parent, ContentInfo pageInfo, PageAdditions? additi
4952
var templateModel = new TemplateModel(request, this, PageInfo, Additions, await Content.GetResourceAsStringAsync().ConfigureAwait(false));
5053

5154
var page = await this.GetPageAsync(request, templateModel).ConfigureAwait(false);
55+
56+
Modifications?.Apply(page);
5257

5358
return page.Build();
5459
}

Modules/Placeholders/Providers/PageProviderBuilder.cs

+59-2
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
using GenHTTP.Api.Infrastructure;
44
using GenHTTP.Api.Content;
55
using GenHTTP.Api.Content.IO;
6+
using GenHTTP.Api.Protocol;
7+
using System;
68

79
namespace GenHTTP.Modules.Placeholders.Providers
810
{
911

10-
public sealed class PageProviderBuilder : IHandlerBuilder<PageProviderBuilder>, IContentInfoBuilder<PageProviderBuilder>, IPageAdditionBuilder<PageProviderBuilder>
12+
public sealed class PageProviderBuilder :
13+
IHandlerBuilder<PageProviderBuilder>,
14+
IContentInfoBuilder<PageProviderBuilder>,
15+
IPageAdditionBuilder<PageProviderBuilder>,
16+
IResponseModification<PageProviderBuilder>
1117
{
1218
private IResource? _Content;
1319

1420
private readonly ContentInfoBuilder _Info = new();
1521

1622
private readonly PageAdditionBuilder _Additions = new();
1723

24+
private readonly ResponseModificationBuilder _Modifications = new();
25+
1826
private readonly List<IConcernBuilder> _Concerns = new();
1927

2028
#region Functionality
@@ -49,6 +57,54 @@ public PageProviderBuilder AddStyle(string path)
4957
return this;
5058
}
5159

60+
public PageProviderBuilder Status(ResponseStatus status)
61+
{
62+
_Modifications.Status(status);
63+
return this;
64+
}
65+
66+
public PageProviderBuilder Status(int status, string reason)
67+
{
68+
_Modifications.Status(status, reason);
69+
return this;
70+
}
71+
72+
public PageProviderBuilder Header(string key, string value)
73+
{
74+
_Modifications.Header(key, value);
75+
return this;
76+
}
77+
78+
public PageProviderBuilder Expires(DateTime expiryDate)
79+
{
80+
_Modifications.Expires(expiryDate);
81+
return this;
82+
}
83+
84+
public PageProviderBuilder Modified(DateTime modificationDate)
85+
{
86+
_Modifications.Modified(modificationDate);
87+
return this;
88+
}
89+
90+
public PageProviderBuilder Cookie(Cookie cookie)
91+
{
92+
_Modifications.Cookie(cookie);
93+
return this;
94+
}
95+
96+
public PageProviderBuilder Type(FlexibleContentType contentType)
97+
{
98+
_Modifications.Type(contentType);
99+
return this;
100+
}
101+
102+
public PageProviderBuilder Encoding(string encoding)
103+
{
104+
_Modifications.Encoding(encoding);
105+
return this;
106+
}
107+
52108
public PageProviderBuilder Add(IConcernBuilder concern)
53109
{
54110
_Concerns.Add(concern);
@@ -62,10 +118,11 @@ public IHandler Build(IHandler parent)
62118
throw new BuilderMissingPropertyException("Content");
63119
}
64120

65-
return Concerns.Chain(parent, _Concerns, (p) => new PageProvider(p, _Info.Build(), _Additions.Build(), _Content));
121+
return Concerns.Chain(parent, _Concerns, (p) => new PageProvider(p, _Info.Build(), _Additions.Build(), _Modifications.Build(), _Content)); ;
66122
}
67123

68124
#endregion
125+
69126
}
70127

71128
}

Testing/Acceptance/Modules/PageTests.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ public async Task TestAdditions()
225225
ModRazor.Page(Resource.FromString("Razor")).AddScript("./myscript.js").AddStyle("./mystyle.css"),
226226
Placeholders.Page(Resource.FromString("Placeholders")).AddScript("http://myserver/myscript.js").AddStyle("http://myserver/mystyle.css"),
227227
CombinedPage.Create().AddMarkdown(Resource.FromString("Scriban")).AddScript("myscript.js").AddStyle("mystyle.css"),
228-
ModMarkdown.Page(Resource.FromString("Markdown")).AddScript("myscript.js").AddStyle("mystyle.css")
228+
ModMarkdown.Page(Resource.FromString("Markdown")).AddScript("myscript.js").AddStyle("mystyle.css"),
229+
Page.From(Resource.FromString("Page")).AddScript("myscript.js").AddStyle("mystyle.css")
229230
};
230231

231232
foreach (var provider in providers)
@@ -252,7 +253,8 @@ public async Task TestModifications()
252253
ModRazor.Page(Resource.FromString("Razor")).Status(ResponseStatus.Locked).Header("H", "V").Expires(DateTime.Now).Modified(DateTime.Now).Type(new(ContentType.FontOpenTypeFont)).Encoding("my-encoding").Cookie(cookie),
253254
Placeholders.Page(Resource.FromString("Placeholders")).Status(ResponseStatus.Locked).Header("H", "V").Expires(DateTime.Now).Modified(DateTime.Now).Type(new(ContentType.FontOpenTypeFont)).Encoding("my-encoding").Cookie(cookie),
254255
ModMarkdown.Page(Resource.FromString("Markdown")).Status(ResponseStatus.Locked).Header("H", "V").Expires(DateTime.Now).Modified(DateTime.Now).Type(new(ContentType.FontOpenTypeFont)).Encoding("my-encoding").Cookie(cookie),
255-
CombinedPage.Create().Add("Combined").Status(ResponseStatus.Locked).Header("H", "V").Expires(DateTime.Now).Modified(DateTime.Now).Type(new(ContentType.FontOpenTypeFont)).Encoding("my-encoding").Cookie(cookie)
256+
CombinedPage.Create().Add("Combined").Status(ResponseStatus.Locked).Header("H", "V").Expires(DateTime.Now).Modified(DateTime.Now).Type(new(ContentType.FontOpenTypeFont)).Encoding("my-encoding").Cookie(cookie),
257+
Page.From(Resource.FromString("Page")).Status(ResponseStatus.Locked).Header("H", "V").Expires(DateTime.Now).Modified(DateTime.Now).Type(new(ContentType.FontOpenTypeFont)).Encoding("my-encoding").Cookie(cookie)
256258
};
257259

258260
foreach (var provider in providers)

0 commit comments

Comments
 (0)