architecture.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. {
  2. title: "Architecture",
  3. crumbs: [
  4. { 'Reference Guide': '../ref/' },
  5. ],
  6. }
  7. <h1>GoAhead Architecture</h1>
  8. <p>The GoAhead web server is the worlds most popular embedded web server and has been embedded in
  9. hundreds of different products and hundreds of millions of devices. GoAhead is a compact and efficient
  10. webserver with simple clean code and APIs.</p>
  11. <p>GoAhead has an strong feature set including:</p>
  12. <ul>
  13. <li>HTTP/1.1</li>
  14. <li>IPv4 and IPv6</li>
  15. <li>TLS/SSL</li>
  16. <li>32 and 64-bit support</li>
  17. <li>HTTP Keep-Alive</li>
  18. <li>Transfer chunk encoding</li>
  19. <li>Server-side Javascript</li>
  20. <li>Basic, Digest and Form-based Authentication</li>
  21. <li>Session state storage</li>
  22. <li>URI routing and rewriting</li>
  23. <li>Logging</li>
  24. <li>Security sandboxing</li>
  25. </ul>
  26. <p>GoAhead is extremely efficient. It runs as a single-threaded, event driven, non-blocking process.
  27. GoAhead is very small (from 600K) and very fast. On a PC class system, it will serve over 10,000 requests per
  28. second.</p>
  29. <a id="components"></a>
  30. <h2 >Core Components</h2>
  31. <p>GoAhead has a modular architecture and clean source code. The key components of GoAhead are:</p>
  32. <table title="Components" class="ui table segment">
  33. <thead>
  34. <tr>
  35. <th class="four wide">Component</th>
  36. <th>Description</th>
  37. </tr>
  38. </thead>
  39. <tbody>
  40. <tr>
  41. <td>GoAhead HTTP Core</td>
  42. <td>Core HTTP server. Includes services for HTTP protocol handling, socket connection
  43. management and logging.</td>
  44. </tr>
  45. <tr>
  46. <td class="nowrap">Request Router</td>
  47. <td>The request router directs client requests to the appropriate request handler. It
  48. enforces user authentication and general redirection and URI rewriting instructions.</td>
  49. </tr>
  50. <tr>
  51. <td class="nowrap">Portable Runtime</td>
  52. <td>Cross-platform, single-threaded, non-blocking event-based portable runtime. Includes services for
  53. memory allocation, safe string handling, lists, hashing, command execution, socket
  54. communications, events, timers, debug trace and logging.</td>
  55. </tr>
  56. <tr>
  57. <td>Authentication Framework</td>
  58. <td>Pluggable authentication. Supports Basic, Digest and Web Form-based authentication schemes.
  59. This includes a Role-based authorization scheme to access to resources can be controlled on
  60. a granular basis.</td>
  61. </tr>
  62. <tr>
  63. <td>Session State</td>
  64. <td>Session state storage. This stores per-user state and cookie management.</td>
  65. </tr>
  66. <tr>
  67. <td>Action Handler</td>
  68. <td>The Action handler binds URIs to C functions for simple, easy access to C-language code.</td>
  69. </tr>
  70. <tr>
  71. <td>File Handler</td>
  72. <td>The File handler serves static content such as HTML pages, images and PDF files.</td>
  73. </tr>
  74. <tr>
  75. <td>Javascript Handler</td>
  76. <td>The Javascript web framework is supports embedded server-side javascript.</td>
  77. </tr>
  78. <tr>
  79. <td>CGI Handler</td>
  80. <td>Common Gateway Interface handler for serving pages by running external CGI programs.</td>
  81. </tr>
  82. <tr>
  83. <td>Secure Sockets Layer (SSL)</td>
  84. <td>Secure Socket Layer protocol stack. This is a virtual interface that can selectively support a
  85. variety of SSL providers including: the MbedTLS and OpenSSL stacks.</td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. <a id="core"></a>
  90. <h2>HTTP Core</h2>
  91. <p>The GoAhead HTTP core is responsible for parsing client HTTP requests and directing
  92. how the request will be processed. The HTTP core reads client requests and parses the request headers.
  93. It then invokes the GoAhead request router to process the request.</p>
  94. <p>The HTTP core includes services for: the main HTTP processing, socket communications, and logging.
  95. The HTTP core server also manages and enforces the sandbox resource limits that have been
  96. defined at build time. These limits enable GoAhead to be more deterministic in its use of system resources and
  97. to be a good system citizen.</p>
  98. <a id="router"></a>
  99. <h2>Request Router</h2>
  100. <p>GoAhead includes a powerful request router that manages how client HTTP requests are processed. The
  101. router is configured with a set of routes from the <i>route.txt</i> configuration.
  102. When a request is received, the router tests various routes and selects the best route to handle
  103. the request. In the process, routes may redirect or rewrite the request as required.</p>
  104. <p>A GoAhead configuration will typically have many routes. The configured routes are tested in-order by
  105. matching the route URI pattern against the request URL. A route may require that further preconditions be met
  106. before it is suitable to process the request. If the required conditions are not met, the next route in the
  107. configuration will be tested. There is always a catch-all route that will process the request if all prior
  108. routes fail to qualify.</p>
  109. <p>Once a route is selected, the specified request handler is invoked to service the request.
  110. GoAhead has handlers for CGI, Javascript and static file data.</p>
  111. <a id="runtime"></a>
  112. <h2>Portable Runtime</h2>
  113. <p>GoAhead is built upon a portable runtime layer that insulates the rest of the
  114. product from the underlying platform and allows it to be highly portable to new operating systems or
  115. hardware.</p>
  116. <p>The GoAhead runtime provides a suite of services that facilitate the creation of secure,
  117. embedded applications including: events, networking, safe string handling, timers, hashing, lists and
  118. logging.</p> <p>The runtime also provides a safer environment in which to program as it replaces 'C' APIs that
  119. are prone to buffer overflows and other similar security exploits. The runtime includes a high performance, safe
  120. string library that supports a secure programming style.</p>
  121. <p>The runtime's event processing can be easily integrated into existing applications. It supports
  122. single and multi-threaded architectures, polled or async event notification. This flexibility means that
  123. GoAhead can be easily integrated into most C/C++ applications.</p>
  124. <p>The runtime includes an optional high performance memory allocator.
  125. This allocator is useful when the native operating system allocator suffers from memory fragmentation.</p>
  126. <a id="dynamic"></a>
  127. <h2 >Dynamic Content</h2>
  128. <a id="cgi"></a>
  129. <h3>CGI</h3>
  130. <p>The Common Gateway Interface (CGI) is a standard for interfacing external applications with web servers. CGI
  131. was originally developed as part of the NCSA HTTP server and is an old standard for interfacing external
  132. applications with HTTP servers. It still enjoys considerable use.</p>
  133. <p>CGI scripts are written in any language that can read from the standard-input, write to the standard-output,
  134. and access environment variables. This means that virtually any programming language can be used, including C,
  135. Perl, or even Unix shell scripting.
  136. See <a href="../users/cgi.html">CGI</a> for more details.</p>
  137. <a id="goactions"></a>
  138. <h3>GoActions</h3>
  139. <p>CGI is a slow technique for creating dynamic web pages as it creates a new process for every request. This is
  140. slow and cumbersome. GoAhead provides a high-performance replacement called GoActions&trade; that is a more
  141. suitable solution for embedded systems that demand compact and efficient solutions.</p>
  142. <p>GoActions are "C" language functions that are bound directly to specific URIs. They respond to client
  143. requests without creating a new process for each request. By sharing the address space with GoAhead, GoActions
  144. can directly access the full request context and device/application specific data.</p>
  145. <p>GoActions are bound to URIs that begin with <i>/action/</i>. When a client requests a URI beginning with
  146. /action, the action handler looks for a defined GoAction of the correct name. Then the bound C function is
  147. invoked to service the request.
  148. See <a href="../users/goactions.html">GoActions</a> for more details.</p>
  149. <a id="jst"></a>
  150. <h3>Javascript Templates</h3>
  151. <p>Javascript Templates (JST) use Javascript code directly embedded in HTML web pages.
  152. The Javascript is run on the server and the result when the code executes is substituted back into the
  153. web page before it is sent to the client.</p>
  154. <p>JST allows the binding of C functions to Javascript functions, so that a JST web page can
  155. easily access device or system data.</p>
  156. <p>See <a href="../users/jst.html">Javascript Templates</a> for more details.</p>
  157. <a id="security"></a>
  158. <h2 >Security</h2>
  159. <p>GoAhead provides a suite of measures designed to increase the security of your web server:</p>
  160. <ul>
  161. <li>Secure Sockets Layer</li>
  162. <li>Authorization directives</li>
  163. <li>Sandbox directives</li>
  164. <li>Secure portable runtime</li>
  165. </ul>
  166. <h3>Secure Sockets</h3>
  167. <p>GoAhead supports the MbedTLS and OpenSSL stacks. You can configure both server and/or client
  168. authentication of certificates. SSL and TLS are supported. Other 3rd party SSL stacks are also available
  169. via the <a href="https://embedthis.com/catalog/">Pak online catalog</a></p>
  170. <h3>Authentication</h3>GoAhead provides Basic, Digest and Web-Form based authentication mechanisms. It
  171. supports both file and PAM-based password backends.
  172. <h3>Sandboxing</h3>
  173. <p>Sandboxing is the term applied to running GoAhead in a confined environment. GoAhead has a set of
  174. build-time directives that define a sandbox which limits the resources that GoAhead may
  175. used.</p>
  176. <a name="apis"></a>
  177. <h2 >Embedding APIs</h2>
  178. <p>GoAhead also provides a detailed API so you can create an embedded web server instance and control
  179. virtual hosts, port binding, directory and location blocks and every other part of GoAhead. See the <a href=
  180. "../ref/api/goahead.html">GoAhead API</a> for full details.</p>
  181. <a id="dirs"></a>
  182. <h2 >GoAhead Directories</h2>
  183. <p>Here is the list of top level directories in the GoAhead source code distribution.</p>
  184. <table title="dirs" class="ui table segment">
  185. <thead><tr><th class="three wide">Name</th><th>Purpose</th></tr></thead>
  186. <tbody>
  187. <tr><td>doc</td><td>Documentation</td></tr>
  188. <tr><td>package</td><td>Packaging scripts</td></tr>
  189. <tr><td>projects</td><td>IDE and Makefile projects</td></tr>
  190. <tr><td>releases</td><td>Release packages</td></tr>
  191. <tr><td>test</td><td>Unit test directory</td></tr>
  192. <tr><td>test/web</td><td>Unit test web documents</td></tr>
  193. <tr><td>utils</td><td>Utility programs</td></tr>
  194. <tr><td>web</td><td>Web documents directory</td></tr>
  195. <tr><td>*/inc</td><td>Master include directory</td></tr>
  196. <tr><td>*/bin</td><td>Output for binaries</td></tr>
  197. <tr><td>*/obj</td><td>Output directory for objects</td></tr>
  198. </tbody>
  199. </table>
  200. <a id="files"></a>
  201. <h2 >GoAhead Files</h2>
  202. <p>Here is a list of the major files in the GoAhead source code distribution.</p>
  203. <table title="files" class="ui table segment">
  204. <thead><tr><th class="three wide">Name</th><th>Purpose</th></tr></thead>
  205. <tbody>
  206. <tr><td>auth.c</td><td>Authorization management</td></tr>
  207. <tr><td>cgi.c</td><td>CGI handler</td></tr>
  208. <tr><td>crypt.c</td><td>Crypto routines</td></tr>
  209. <tr><td>file.c</td><td>File handler for static documents</td></tr>
  210. <tr><td>galloc.c</td><td>Optional fast memory allocator</td></tr>
  211. <tr><td>goahead.c</td><td>GoAhead server main program</td></tr>
  212. <tr><td>goahead.h</td><td>GoAhead master include header</td></tr>
  213. <tr><td>http.c</td><td>HTTP core engine</td></tr>
  214. <tr><td>js.c</td><td>GoAhead Javascript language</td></tr>
  215. <tr><td>js.h</td><td>Javascript header</td></tr>
  216. <tr><td>jst.c</td><td>Javascript Templates handler</td></tr>
  217. <tr><td>options.c</td><td>Options and Trace method handlers</td></tr>
  218. <tr><td>rom-documents.c</td><td>Compiled web pages into C code</td></tr>
  219. <tr><td>rom.c</td><td>ROM file system</td></tr>
  220. <tr><td>route.c</td><td>Request router</td></tr>
  221. <tr><td>route.txt</td><td>Route configuration</td></tr>
  222. <tr><td>runtime.c</td><td>Portable runtime layer</td></tr>
  223. <tr><td>socket.c</td><td>Socket management</td></tr>
  224. <tr><td>upload.c</td><td>File upload handler</td></tr>
  225. </tbody>
  226. </table>
  227. <a id="additional"></a>
  228. <h3 >GoAhead Additional Files</h3>
  229. <table title="additional" class="ui table segment">
  230. <thead><tr><th class="three wide">Name</th><th>Purpose</th></tr></thead>
  231. <tbody>
  232. <tr><td>configure</td><td>Configuration script</td></tr>
  233. <tr><td>Makefile</td><td>Top-level Makefile</td></tr>
  234. <tr><td>main.me</td><td>Primary MakeMe configuration</td></tr>
  235. <tr><td>*/inc/me.h</td><td>Generated MakeMe include header</td></tr>
  236. <tr><td>build/OS-ARCH-PROFILE/platform.me</td><td>Generated MakeMe configuration file</td></tr>
  237. <tr><td>server.key.pem</td><td>Test SSL private key</td></tr>
  238. <tr><td>server.crt</td><td>Test SSL certificate</td></tr>
  239. </tbody>
  240. </table>