BaseUrlHtmlRewriter Pennington.Infrastructure
Prefixes root-relative URLs (href, src, action) with the configured base URL. Also stamps data-base-url on <body> so client-side code can reproduce the same prefix on dynamically-generated links.
Outermost transport layer — Order 30, so xref (10) and locale rewriting (20) both operate on logical root-relative paths without having to strip the base URL first.
Properties
Orderint- Sort order within the HTML rewriting pipeline. Rewriters run in ascending
Order. Xref resolution at 10, locale prefixing at 20, base-URL prefixing at 30 — the outside-in order that was previously expressed across separateIResponseProcessors.
Constructors
.ctor
#public BaseUrlHtmlRewriter(OutputOptions? outputOptions);Initializes the rewriter with the base URL from OutputOptions.
Parameters
outputOptionsOutputOptions?
Methods
ApplyAsync
#public Task ApplyAsync(IDocument document, HttpContext context);Mutate the shared parsed document. The orchestrator serializes it once after every rewriter has run.
Parameters
documentIDocumentcontextHttpContext
Returns
TaskShouldApply
#public bool ShouldApply(HttpContext context);Cheap gate checked before parsing. Return false to skip both PreParseAsync and ApplyAsync for this response. If every rewriter returns false, the orchestrator skips parsing entirely.
Parameters
contextHttpContext
Returns
boolPennington.Infrastructure.BaseUrlHtmlRewriter
namespace Pennington.Infrastructure;
/// Prefixes root-relative URLs (href, src, action) with the configured base URL. Also stamps data-base-url on <body> so client-side code can reproduce the same prefix on dynamically-generated links. Outermost transport layer — Order 30, so xref (10) and locale rewriting (20) both operate on logical root-relative paths without having to strip the base URL first.
public class BaseUrlHtmlRewriter
{
/// Initializes the rewriter with the base URL from OutputOptions.
public BaseUrlHtmlRewriter(OutputOptions? outputOptions);
/// Mutate the shared parsed document. The orchestrator serializes it once after every rewriter has run.
public Task ApplyAsync(IDocument document, HttpContext context);
/// Sort order within the HTML rewriting pipeline. Rewriters run in ascending Order. Xref resolution at 10, locale prefixing at 20, base-URL prefixing at 30 — the outside-in order that was previously expressed across separate IResponseProcessors.
public int Order => 30;
/// Cheap gate checked before parsing. Return false to skip both PreParseAsync and ApplyAsync for this response. If every rewriter returns false, the orchestrator skips parsing entirely.
public bool ShouldApply(HttpContext context);
}