205 lines
12 KiB
HTML
205 lines
12 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang>
|
|
<head>
|
|
<!-- Generated by javadoc (21) on Tue May 12 13:57:37 UTC 2026 -->
|
|
<title>Middleware (flash-parent 2.0.0 API)</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<meta name="dc.created" content="2026-05-12">
|
|
<meta name="description" content="declaration: package: dev.relism.flash.routing, interface: Middleware">
|
|
<meta name="generator" content="javadoc/ClassWriterImpl">
|
|
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
|
|
<link rel="stylesheet" type="text/css" href="../../../../script-dir/jquery-ui.min.css" title="Style">
|
|
<script type="text/javascript" src="../../../../script.js"></script>
|
|
<script type="text/javascript" src="../../../../script-dir/jquery-3.7.1.min.js"></script>
|
|
<script type="text/javascript" src="../../../../script-dir/jquery-ui.min.js"></script>
|
|
</head>
|
|
<body class="class-declaration-page">
|
|
<script type="text/javascript">var pathtoroot = "../../../../";
|
|
loadScripts(document, 'script');</script>
|
|
<noscript>
|
|
<div>JavaScript is disabled on your browser.</div>
|
|
</noscript>
|
|
<div class="flex-box">
|
|
<header role="banner" class="flex-header">
|
|
<nav role="navigation">
|
|
<!-- ========= START OF TOP NAVBAR ======= -->
|
|
<div class="top-nav" id="navbar-top"><button id="navbar-toggle-button" aria-controls="navbar-top" aria-expanded="false" aria-label="Toggle navigation links"><span class="nav-bar-toggle-icon"> </span><span class="nav-bar-toggle-icon"> </span><span class="nav-bar-toggle-icon"> </span></button>
|
|
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
|
|
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
|
|
<li><a href="../../../../index.html">Overview</a></li>
|
|
<li><a href="package-summary.html">Package</a></li>
|
|
<li class="nav-bar-cell1-rev">Class</li>
|
|
<li><a href="class-use/Middleware.html">Use</a></li>
|
|
<li><a href="package-tree.html">Tree</a></li>
|
|
<li><a href="../../../../index-all.html">Index</a></li>
|
|
<li><a href="../../../../help-doc.html#class">Help</a></li>
|
|
</ul>
|
|
<ul class="sub-nav-list-small">
|
|
<li>
|
|
<p>Summary:</p>
|
|
<ul>
|
|
<li>Nested</li>
|
|
<li>Field</li>
|
|
<li>Constr</li>
|
|
<li><a href="#method-summary">Method</a></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>Detail:</p>
|
|
<ul>
|
|
<li>Field</li>
|
|
<li>Constr</li>
|
|
<li><a href="#method-detail">Method</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="sub-nav">
|
|
<div id="navbar-sub-list">
|
|
<ul class="sub-nav-list">
|
|
<li>Summary: </li>
|
|
<li>Nested | </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method-summary">Method</a></li>
|
|
</ul>
|
|
<ul class="sub-nav-list">
|
|
<li>Detail: </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method-detail">Method</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="nav-list-search"><a href="../../../../search.html">SEARCH</a>
|
|
<input type="text" id="search-input" disabled placeholder="Search">
|
|
<input type="reset" id="reset-button" disabled value="reset">
|
|
</div>
|
|
</div>
|
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
|
<span class="skip-nav" id="skip-navbar-top"></span></nav>
|
|
</header>
|
|
<div class="flex-content">
|
|
<main role="main">
|
|
<!-- ======== START OF CLASS DATA ======== -->
|
|
<div class="header">
|
|
<div class="sub-title"><span class="package-label-in-type">Package</span> <a href="package-summary.html">dev.relism.flash.routing</a></div>
|
|
<h1 title="Interface Middleware" class="title">Interface Middleware</h1>
|
|
</div>
|
|
<section class="class-description" id="class-description">
|
|
<dl class="notes">
|
|
<dt>Functional Interface:</dt>
|
|
<dd>This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.</dd>
|
|
</dl>
|
|
<hr>
|
|
<div class="type-signature"><span class="annotations"><a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/FunctionalInterface.html" title="class or interface in java.lang" class="external-link">@FunctionalInterface</a>
|
|
</span><span class="modifiers">public interface </span><span class="element-name type-name-label">Middleware</span></div>
|
|
<div class="block">Stateless interceptor applied around a <a href="../models/RequestHandler.html" title="class in dev.relism.flash.models"><code>RequestHandler</code></a>.
|
|
|
|
<p>Middleware is composed <em>once at registration time</em> and stored as a pre-built handler
|
|
chain inside the router's state machine. There is zero runtime overhead: no lists are visited,
|
|
no lookups performed, and no objects allocated on the request hot-path.
|
|
|
|
<p>Middleware is intentionally stateless — it can read <a href="../models/Request.html" title="class in dev.relism.flash.models"><code>Request</code></a>,
|
|
write to <a href="../models/Response.html" title="class in dev.relism.flash.models"><code>Response</code></a>, and decide whether to call <code>next</code> or
|
|
short-circuit. Shared state between layers belongs in HDI handler chains, not here.
|
|
|
|
<pre><code>
|
|
// Inline definition — pure lambda, no wrapper types needed
|
|
Middleware auth = next -> (req, res) -> {
|
|
if (req.header("Authorization") == null) { res.status(401); return null; }
|
|
return next.handle(req, res);
|
|
};
|
|
|
|
// Named reusable chain — composed into a single object at call time
|
|
Middleware secured = Middleware.of(cors, auth, rateLimit);
|
|
|
|
// Router-level: applied to every handler registered on this router
|
|
AbstractRouter api = new MyRouter(cors, auth);
|
|
|
|
// Handler-level: applied only to this route
|
|
app.get("/admin", (req, res) -> "secret", auth);
|
|
app.get("/log", handler, logging, auth);
|
|
</code></pre></div>
|
|
</section>
|
|
<section class="summary">
|
|
<ul class="summary-list">
|
|
<!-- ========== METHOD SUMMARY =========== -->
|
|
<li>
|
|
<section class="method-summary" id="method-summary">
|
|
<h2>Method Summary</h2>
|
|
<div id="method-summary-table">
|
|
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab1" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab1', 3)" class="table-tab">Static Methods</button><button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="table-tab">Instance Methods</button><button id="method-summary-table-tab3" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab3', 3)" class="table-tab">Abstract Methods</button></div>
|
|
<div id="method-summary-table.tabpanel" role="tabpanel" aria-labelledby="method-summary-table-tab0">
|
|
<div class="summary-table three-column-summary">
|
|
<div class="table-header col-first">Modifier and Type</div>
|
|
<div class="table-header col-second">Method</div>
|
|
<div class="table-header col-last">Description</div>
|
|
<div class="col-first even-row-color method-summary-table method-summary-table-tab1"><code>static <a href="Middleware.html" title="interface in dev.relism.flash.routing">Middleware</a></code></div>
|
|
<div class="col-second even-row-color method-summary-table method-summary-table-tab1"><code><a href="#of(dev.relism.flash.routing.Middleware...)" class="member-name-link">of</a><wbr>(<a href="Middleware.html" title="interface in dev.relism.flash.routing">Middleware</a>... chain)</code></div>
|
|
<div class="col-last even-row-color method-summary-table method-summary-table-tab1">
|
|
<div class="block">Composes an ordered chain of middlewares into a single <a href="Middleware.html" title="interface in dev.relism.flash.routing"><code>Middleware</code></a>.</div>
|
|
</div>
|
|
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="../models/SimpleHandler.FunctionalHandler.html" title="interface in dev.relism.flash.models">SimpleHandler.FunctionalHandler</a></code></div>
|
|
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#wrap(dev.relism.flash.models.RequestHandler)" class="member-name-link">wrap</a><wbr>(<a href="../models/RequestHandler.html" title="class in dev.relism.flash.models">RequestHandler</a> next)</code></div>
|
|
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
|
|
<div class="block">Wraps <code>next</code> with this middleware's logic.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section class="details">
|
|
<ul class="details-list">
|
|
<!-- ============ METHOD DETAIL ========== -->
|
|
<li>
|
|
<section class="method-details" id="method-detail">
|
|
<h2>Method Details</h2>
|
|
<ul class="member-list">
|
|
<li>
|
|
<section class="detail" id="wrap(dev.relism.flash.models.RequestHandler)">
|
|
<h3>wrap</h3>
|
|
<div class="member-signature"><span class="return-type"><a href="../models/SimpleHandler.FunctionalHandler.html" title="interface in dev.relism.flash.models">SimpleHandler.FunctionalHandler</a></span> <span class="element-name">wrap</span><wbr><span class="parameters">(<a href="../models/RequestHandler.html" title="class in dev.relism.flash.models">RequestHandler</a> next)</span></div>
|
|
<div class="block">Wraps <code>next</code> with this middleware's logic. Called <em>once at boot time</em>
|
|
during handler registration. Returns a <a href="../models/SimpleHandler.FunctionalHandler.html" title="interface in dev.relism.flash.models"><code>SimpleHandler.FunctionalHandler</code></a> lambda
|
|
— no wrapper types required at the call site.
|
|
|
|
<p>The returned functional handler is boxed into a <a href="../models/SimpleHandler.html" title="class in dev.relism.flash.models"><code>SimpleHandler</code></a> internally by
|
|
<a href="AbstractRouter.html" title="class in dev.relism.flash.routing"><code>AbstractRouter</code></a>; callers never need to do this manually.</div>
|
|
</section>
|
|
</li>
|
|
<li>
|
|
<section class="detail" id="of(dev.relism.flash.routing.Middleware...)">
|
|
<h3>of</h3>
|
|
<div class="member-signature"><span class="modifiers">static</span> <span class="return-type"><a href="Middleware.html" title="interface in dev.relism.flash.routing">Middleware</a></span> <span class="element-name">of</span><wbr><span class="parameters">(<a href="Middleware.html" title="interface in dev.relism.flash.routing">Middleware</a>... chain)</span></div>
|
|
<div class="block">Composes an ordered chain of middlewares into a single <a href="Middleware.html" title="interface in dev.relism.flash.routing"><code>Middleware</code></a>.
|
|
The first element is the outermost wrapper and therefore executes first.
|
|
|
|
<p>The composition loop runs once when <a href="#wrap(dev.relism.flash.models.RequestHandler)"><code>wrap(dev.relism.flash.models.RequestHandler)</code></a> is called (i.e. at registration
|
|
time), not at construction of the chain. Zero allocations on the hot-path.
|
|
|
|
<pre><code>
|
|
Middleware secured = Middleware.of(cors, auth, rateLimit);
|
|
// execution order: cors → auth → rateLimit → handler
|
|
</code></pre></div>
|
|
</section>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<!-- ========= END OF CLASS DATA ========= -->
|
|
</main>
|
|
<footer role="contentinfo">
|
|
<hr>
|
|
<p class="legal-copy"><small>Copyright © 2026. All rights reserved.</small></p>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|