GCR deployment testing in progress - content type issue still remaining.

This commit is contained in:
2026-05-05 14:42:03 +05:00
parent 40fe69ed65
commit f2d02a23ec
35 changed files with 2316 additions and 2431 deletions
+31
View File
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Http;
namespace Htmx.ApiDemo;
/// <summary>
/// IResult implementation for rendering Htmx components as HTML or issuing redirects.
/// Defined as user code (not source-generated) so that RequestDelegateGenerator can
/// see it and emit NativeAOT-safe endpoint interceptors for lambdas returning this type.
/// </summary>
public readonly struct HtmxResult : IResult
{
private readonly IHtmxComponent? _component;
private readonly string? _redirectUrl;
public HtmxResult(IHtmxComponent component) { _component = component; _redirectUrl = null; }
public HtmxResult(string redirectUrl) { _component = null; _redirectUrl = redirectUrl; }
public Task ExecuteAsync(HttpContext context)
{
if (_redirectUrl is not null)
{
context.Response.Redirect(_redirectUrl);
return Task.CompletedTask;
}
context.Response.ContentType = "text/html; charset=utf-8";
var writerContext = new HtmxRenderContext(context.Response.BodyWriter);
_component!.Render(writerContext);
return Task.CompletedTask;
}
}