|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 | +<html> |
| 4 | +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 5 | +<head> |
| 6 | + <title>Pegasus webserver in Lua</title> |
| 7 | + <link rel="stylesheet" href="../ldoc.css" type="text/css" /> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + |
| 11 | +<div id="container"> |
| 12 | + |
| 13 | +<div id="product"> |
| 14 | + <div id="product_logo"></div> |
| 15 | + <div id="product_name"><big><b></b></big></div> |
| 16 | + <div id="product_description"></div> |
| 17 | +</div> <!-- id="product" --> |
| 18 | + |
| 19 | + |
| 20 | +<div id="main"> |
| 21 | + |
| 22 | + |
| 23 | +<!-- Menu --> |
| 24 | + |
| 25 | +<div id="navigation"> |
| 26 | +<br/> |
| 27 | +<h1>Pegasus</h1> |
| 28 | + |
| 29 | + |
| 30 | +<ul> |
| 31 | + <li><a href="../index.html">Index</a></li> |
| 32 | +</ul> |
| 33 | + |
| 34 | +<h2>Contents</h2> |
| 35 | +<ul> |
| 36 | +<li><a href="#Functions">Functions</a></li> |
| 37 | +</ul> |
| 38 | + |
| 39 | + |
| 40 | +<h2>Classes</h2> |
| 41 | +<ul class="nowrap"> |
| 42 | + <li><a href="../classes/pegasus.html">pegasus</a></li> |
| 43 | + <li><strong>pegasus.handler</strong></li> |
| 44 | + <li><a href="../classes/pegasus.plugins.compress.html">pegasus.plugins.compress</a></li> |
| 45 | + <li><a href="../classes/pegasus.plugins.downloads.html">pegasus.plugins.downloads</a></li> |
| 46 | + <li><a href="../classes/pegasus.plugins.files.html">pegasus.plugins.files</a></li> |
| 47 | + <li><a href="../classes/pegasus.plugins.router.html">pegasus.plugins.router</a></li> |
| 48 | + <li><a href="../classes/pegasus.plugins.tls.html">pegasus.plugins.tls</a></li> |
| 49 | + <li><a href="../classes/pegasus.request.html">pegasus.request</a></li> |
| 50 | + <li><a href="../classes/pegasus.response.html">pegasus.response</a></li> |
| 51 | +</ul> |
| 52 | +<h2>Modules</h2> |
| 53 | +<ul class="nowrap"> |
| 54 | + <li><a href="../modules/logging.html">logging</a></li> |
| 55 | +</ul> |
| 56 | +<h2>Topics</h2> |
| 57 | +<ul class=""> |
| 58 | + <li><a href="../topics/LICENSE.html">LICENSE</a></li> |
| 59 | + <li><a href="../topics/README.md.html">README</a></li> |
| 60 | +</ul> |
| 61 | +<h2>Examples</h2> |
| 62 | +<ul class="nowrap"> |
| 63 | + <li><a href="../examples/app.lua.html">app.lua</a></li> |
| 64 | + <li><a href="../examples/app_stream.lua.html">app_stream.lua</a></li> |
| 65 | + <li><a href="../examples/copas.lua.html">copas.lua</a></li> |
| 66 | + <li><a href="../examples/querystring.lua.html">querystring.lua</a></li> |
| 67 | + <li><a href="../examples/write.lua.html">write.lua</a></li> |
| 68 | +</ul> |
| 69 | + |
| 70 | +</div> |
| 71 | + |
| 72 | +<div id="content"> |
| 73 | + |
| 74 | +<h1>Class <code>pegasus.handler</code></h1> |
| 75 | +<p>Internal handler that drives the request/response cycle.</p> |
| 76 | +<p> |
| 77 | + |
| 78 | + |
| 79 | +<p> Internal orchestrator that wires the server socket to request/response |
| 80 | + objects and drives the plugin pipeline.</p> |
| 81 | + |
| 82 | +<p> Lifecycle for each connection/request:</p> |
| 83 | + |
| 84 | +<ol> |
| 85 | + <li><code>pluginsNewConnection(client)</code> can wrap/replace or reject the client</li> |
| 86 | + <li>Request/Response objects are created</li> |
| 87 | + <li><code>pluginsNewRequestResponse(request, response)</code> runs</li> |
| 88 | + <li><code>pluginsBeforeProcess(request, response)</code> runs</li> |
| 89 | + <li>User <code>callback(request, response)</code> is invoked</li> |
| 90 | + <li><code>pluginsAfterProcess(request, response)</code> runs</li> |
| 91 | + <li>If response not closed, a default 404 is written</li> |
| 92 | +</ol> |
| 93 | + |
| 94 | +<p> Plugins may also:</p> |
| 95 | + |
| 96 | +<ul> |
| 97 | + <li>modify Request/Response metatables via <code>alterRequestResponseMetaTable</code></li> |
| 98 | + <li>intercept file processing via <code>processFile</code></li> |
| 99 | + <li>filter/transform streamed body via <code>processBodyData</code></li> |
| 100 | +</ul> |
| 101 | + |
| 102 | +<p> Minimal plugin example:</p> |
| 103 | + |
| 104 | + |
| 105 | +<pre> |
| 106 | +<span class="keyword">local</span> MyPlugin = {} |
| 107 | + |
| 108 | +<span class="keyword">function</span> MyPlugin:<span class="function-name">new</span>() |
| 109 | + <span class="keyword">return</span> <span class="global">setmetatable</span>({}, { __index = self }) |
| 110 | +<span class="keyword">end</span> |
| 111 | + |
| 112 | +<span class="keyword">function</span> MyPlugin:<span class="function-name">beforeProcess</span>(req, res) |
| 113 | + res:<span class="function-name">addHeader</span>(<span class="string">'X-Powered-By'</span>, <span class="string">'Pegasus'</span>) |
| 114 | +<span class="keyword">end</span> |
| 115 | + |
| 116 | +<span class="keyword">return</span> MyPlugin |
| 117 | +</pre> |
| 118 | + |
| 119 | +</p> |
| 120 | + |
| 121 | + |
| 122 | +<h2><a href="#Functions">Functions</a></h2> |
| 123 | +<table class="function_list"> |
| 124 | + <tr> |
| 125 | + <td class="name" nowrap><a href="#Handler:new">Handler:new (callback, location, plugins, logger)</a></td> |
| 126 | + <td class="summary">Construct a <code>Handler</code>.</td> |
| 127 | + </tr> |
| 128 | + <tr> |
| 129 | + <td class="name" nowrap><a href="#Handler:processRequest">Handler:processRequest (port, client, server)</a></td> |
| 130 | + <td class="summary">Process a single client by creating <code>Request</code>/<code>Response</code> and running pipeline.</td> |
| 131 | + </tr> |
| 132 | +</table> |
| 133 | + |
| 134 | +<br/> |
| 135 | +<br/> |
| 136 | + |
| 137 | + |
| 138 | + <h2 class="section-header "><a name="Functions"></a>Functions</h2> |
| 139 | + Methods |
| 140 | + <dl class="function"> |
| 141 | + <dt> |
| 142 | + <a name = "Handler:new"></a> |
| 143 | + <strong>Handler:new (callback, location, plugins, logger)</strong> |
| 144 | + </dt> |
| 145 | + <dd> |
| 146 | + Construct a <code>Handler</code>. </p> |
| 147 | + |
| 148 | +<p> When <code>location</code> is a non-empty string, automatically enables the <code>files</code> |
| 149 | + plugin to serve static files from that directory (default index <code>/index.html</code>). |
| 150 | + |
| 151 | + |
| 152 | + <h3>Parameters:</h3> |
| 153 | + <ul> |
| 154 | + <li><span class="parameter">callback</span> |
| 155 | + <span class="types"><span class="type">function</span></span> |
| 156 | + using signature <code>stop_further_processing = function(request, response)</code> |
| 157 | + </li> |
| 158 | + <li><span class="parameter">location</span> |
| 159 | + <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span> |
| 160 | + base directory for static files (optional) |
| 161 | + </li> |
| 162 | + <li><span class="parameter">plugins</span> |
| 163 | + <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.6">table</a></span> |
| 164 | + list of plugin instances (optional) |
| 165 | + </li> |
| 166 | + <li><span class="parameter">logger</span> |
| 167 | + <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.6">table</a></span> |
| 168 | + logger instance (optional) |
| 169 | + </li> |
| 170 | + </ul> |
| 171 | + |
| 172 | + <h3>Returns:</h3> |
| 173 | + <ol> |
| 174 | + |
| 175 | + <span class="types"><span class="type">Handler</span></span> |
| 176 | + handler |
| 177 | + </ol> |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | +</dd> |
| 183 | + <dt> |
| 184 | + <a name = "Handler:processRequest"></a> |
| 185 | + <strong>Handler:processRequest (port, client, server)</strong> |
| 186 | + </dt> |
| 187 | + <dd> |
| 188 | + Process a single client by creating <code>Request</code>/<code>Response</code> and running pipeline. |
| 189 | + If the callback does not close the response, a default 404 page is sent. |
| 190 | + |
| 191 | + |
| 192 | + <h3>Parameters:</h3> |
| 193 | + <ul> |
| 194 | + <li><span class="parameter">port</span> |
| 195 | + <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a> or <span class="type">number</span></span> |
| 196 | + server port |
| 197 | + </li> |
| 198 | + <li><span class="parameter">client</span> |
| 199 | + <span class="types"><span class="type">socket</span></span> |
| 200 | + accepted client socket |
| 201 | + </li> |
| 202 | + <li><span class="parameter">server</span> |
| 203 | + <span class="types"><span class="type">socket</span></span> |
| 204 | + listening server socket |
| 205 | + </li> |
| 206 | + </ul> |
| 207 | + |
| 208 | + <h3>Returns:</h3> |
| 209 | + <ol> |
| 210 | + |
| 211 | + <span class="types"><span class="type">boolean</span> or <span class="type">nil</span></span> |
| 212 | + <code>false</code> when connection was rejected by a plugin, <code>nil</code> on normal completion |
| 213 | + </ol> |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | +</dd> |
| 219 | +</dl> |
| 220 | + |
| 221 | + |
| 222 | +</div> <!-- id="content" --> |
| 223 | +</div> <!-- id="main" --> |
| 224 | +<div id="about"> |
| 225 | +<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> |
| 226 | +<i style="float:right;">Last updated 2026-03-04 12:03:10 </i> |
| 227 | +</div> <!-- id="about" --> |
| 228 | +</div> <!-- id="container" --> |
| 229 | +</body> |
| 230 | +</html> |
0 commit comments