v2026.11.2
All Bundles
Bundle

HTTP server framework. WebServer registers route handlers for GET/POST/PUT/DELETE, parses query params and multipart form data, and supports OAuth token exchange. Compile with -lib net_server.

StaticFiles

Serves the files under a folder, for a site: content types from a whitelist of file extensions (anything else is a 404), index.html for a folder, ETag and conditional requests (304), gzip for text, and Range for large files. Small files are kept in a memory cache with a total budget; large ones are read from disk for each request, and a Range request reads only the slice it asks for. A file that changes on disk is served fresh, since its size and modification time are checked on every request.

Refused as 404: dotfiles and anything in a dot folder, extensions not on the list, names that are not plain ASCII. Folder listings are never produced. The request target has already been checked by the server (no "..", encoded separators, NUL, and so on) before a handler runs; this class checks it again. It does not follow or detect symbolic links, so the folder it serves must not contain any.

Example

class SiteHandler from HttpRequestHandler {
  New() { Parent(); }

  method : ProcessGet(request : Request, response : Response) ~ Bool {
    Site->Files()->Serve(request, response);
    return false;
  }

  method : ProcessPost(request : Request, response : Response) ~ Bool {
    return false;
  }
}

Operations

New # constructor

Constructor

New(root:String)

Parameters

NameTypeDescription
rootStringfolder to serve

Serve #

Answers a request for a file: sets the response code, headers and content.

method : public : Serve(request:Request, response:Response) ~ Nil

Parameters

NameTypeDescription
requestRequestthe request
responseResponsethe response

SetCacheLimits #

Sets the memory the cache may use and the largest file it will hold. A file over small_bytes is read from disk for every request.

method : public : SetCacheLimits(total_bytes:Int, small_bytes:Int) ~ Nil

Parameters

NameTypeDescription
total_bytesIntcache budget in bytes, 64 MB by default
small_bytesIntlargest cached file in bytes, 1 MB by default