This guide explains the HTTP server examples under ./examples/net/http_* and the supporting standard library modules under ./lib/net/.
It covers what each example does, how to run it, and how the request handling/CGI pieces are implemented.
fun executable, or ensure fun is on your PATH../build_debug/fun or ./build_release/fun../examples/data/htdocs by default.FUN_LIB_DIR — path to the stdlib (./lib when running from the repo).FUN_EXEC — override path to the fun interpreter used to run CGI children.FUN_HTDOCS — override htdocs directory for some examples (not all).FUN_PORT — override port for some examples (mainly the MT CGI one).net/http_server.fun — Simple blocking HTTP server class serving static files, with a very small built-in “CGI for .fun files” (spawns fun with QUERY_STRING/POST_DATA).net/http_cgi_server.fun — Blocking server with fuller CGI support using net/cgi.fun to translate CGI output into proper HTTP responses and richer request/header parsing.net/http_cgi_lib_server.fun — Variant of the CGI server with the same core behavior, explicitly wiring the Fun interpreter path and using CGI().cgi_to_http_response() from net/cgi.fun.net/cgi.fun — Helpers to work with CGI-style programs and to translate CGI output (headers + body) into full HTTP/1.1 responses.See documentation/stdlib.md → net/ for a quick index of these modules.
examples/net/http_static_server.funio/socket.fun8088, backlog 10.TcpServer(port, backlog) → listen() → loop on accept()sock_recv() reads and discards requestContent-Length and Connection: closesock_send() and closes the client./examples/net/http_static_server.funexamples/net/http_server.fun#include <net/http_server.fun> (class HTTPServer).fun, it spawns fun to run the script and returns its output.8080./examples/data/htdocslib/net/http_server.fun):method and path; / maps to /index.html..fun, builds a small environment:QUERY_STRING (for ?a=b), POST_DATA (raw body when POST).proc_run("<env> fun <script>") and uses out as response body.htdocs and serves it as-is.Content-Type: text/html, Content-Length, Connection: close../examples/net/http_server.fun/hello.fun?name=Fun.examples/net/http_server_cgi.fun#include <net/http_cgi_server.fun> (class HTTPCGIServer).fun scripts under htdocs via a child Fun interpreter, with fuller CGI environment and header handling.8080./examples/data/htdocslib/net/http_cgi_server.fun):/ → /index.html; .fun → treat as CGI script.FUN_LIB_DIR, REQUEST_METHOD, QUERY_STRING, SCRIPT_NAME, PATH_INFO, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, HTTP_HOST, HTTP_USER_AGENT, HTTP_COOKIE, CONTENT_TYPE, CONTENT_LENGTH, and POST_DATA (if any).$FUN_EXEC → ./build_debug/fun → ./build_release/fun → fun from PATH.net/cgi.fun to convert CGI output (headers + body) into a proper HTTP/1.1 response before sending../examples/net/http_server_cgi.fun/, /hello.fun?name=Fun, /info.fun under http://127.0.0.1:8080/examples/net/http_server_cgi_lib.fun#include <net/http_cgi_lib_server.fun> (class HTTPCGILibServer)CGI().cgi_to_http_response() for translating CGI output.HTTPCGIServer: static files from htdocs, .fun as CGI with the same env block and interpreter selection logic../examples/net/http_server_cgi_lib.fun/, /hello.fun?name=Fun, /info.fun under http://127.0.0.1:8080/examples/net/http_mt_server.funio/socket.fun, io/thread.funaccept(), each connection handled in a new Fun thread.PORT = 8080, BACKLOG = 128 (note the comment mentions 8089 in a usage line; the code uses 8080)../examples/net/http_mt_server.fun then open http://127.0.0.1:8080/examples/net/http_mt_server_cgi.funio/socket.fun, io/thread.fun, net/cgi.fun.fun scripts as CGI, implemented without higher-level string helpers to keep per-thread globals minimal.PORT = 8080, BACKLOG = 128, HTDOCS = ./examples/data/htdocs.method and target.path and query on ?; / becomes /index.html.path ends with .fun: build CGI env; spawn a child fun to execute the script; capture stdout; translate to HTTP via _cgi_to_http_response(); send back.HTDOCS + path; send 200 or 404.FUN_LIB_DIR, REQUEST_METHOD, QUERY_STRING, SCRIPT_NAME, PATH_INFO, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, HTTP_HOST, HTTP_USER_AGENT, HTTP_COOKIE, CONTENT_TYPE, CONTENT_LENGTH, POST_DATA (when present).$FUN_EXEC → ./build_debug/fun → ./build_release/fun → fun from PATH.HTDOCS & port via FUN_HTDOCS and FUN_PORT environment variables._trim, _ends_with, _split_*) to avoid heavy string utilities inside threads../examples/net/http_mt_server_cgi.fun then open http://127.0.0.1:8080/examples/net/http_server_test.fun/ to /index.html under the configured htdocs directory.<htdocs><path>; a missing file returns 404 Not Found..fun under htdocs is executed with the Fun interpreter as a child process.net/cgi.fun or a local helper).#include stdlib modules, FUN_LIB_DIR is populated (defaults to ./lib when run from repo root).Content-Type: text/html; charset=utf-8 by default for dynamic responses; static file content types are not auto-detected in these examples.Connection: close; examples do not implement keep-alive or HTTP/1.1 request pipelining.set_htdocs("/path/to/site") on the server instance before start().FUN_HTDOCS=/path/to/site in the environment before launch..fun directly with your fun interpreter and fix any errors.FUN_LIB_DIR points to the stdlib (especially when running CGI scripts that #include modules).