CL-HTTP Chapter 1: CL-HTTP Overview and Architecture


Reference Manual | Next: Chapter 2. Installation and Configuration


Contents

  1. 1.1 What is CL-HTTP
  2. 1.2 Design Philosophy
  3. 1.3 Package Architecture
  4. 1.4 Directory Structure
  5. 1.5 Supported Platforms
  6. 1.6 Feature Flags

1.1 What is CL-HTTP

CL-HTTP is the Common Lisp Hypermedia Server, a comprehensive web application framework developed since 1994 at the MIT Computer Science & Artificial Intelligence Laboratory by John C. Mallery, with contributions from the Lisp community. It is a complete, production-quality platform for building dynamic web applications in Common Lisp.

Published Papers

The CL-HTTP architecture and subsystems are described in these papers:

CL-HTTP provides:

The system is freely distributed with complete source code (portable and platform-specific) and has been proven in major production systems and top research laboratories.

1.2 Design Philosophy

CL-HTTP's architecture is built on several key design principles that distinguish it from other web servers and application frameworks.

1.2.1 Package-Based Portability

CL-HTTP keeps all portable code free of implementation-specific conditionalizations. Platform-specific code is isolated in two packages — IPC and WWW-UTILS — that export a unified interface. The portable HTTP package inherits platform-specific functionality through the Common Lisp package system without knowing which Lisp implementation it runs on. This design has allowed CL-HTTP to be ported to eight Common Lisp implementations spanning Lisp machines, workstations, and modern platforms.

1.2.2 Object-Oriented Architecture with MOP

CL-HTTP uses CLOS (the Common Lisp Object System) pervasively. URLs, server instances, authentication objects, conditions, log objects, and export types are all represented as CLOS classes. The Meta-Object Protocol (MOP) is used for class introspection, and generic functions define the extension protocols. New behavior is added by specializing methods, not by editing existing code.

1.2.3 Computed Responses

Rather than relying on CGI scripts or template engines, CL-HTTP uses response functions — Lisp functions that compute HTTP responses directly. A response function receives the URL object and the HTTP stream, and writes the response using the full power of Common Lisp. This approach is more powerful than Java Servlets and eliminates the overhead of process creation and string-based inter-process communication.

(http:export-url #u"/my-page.html"
                 :computed
                 :response-function #'write-my-page
                 :expiration '(:interval 3600)
                 :keywords '(:example))

1.2.4 HTML Generation Macros

CL-HTTP generates HTML through Lisp macros rather than templates. Each HTML element has a corresponding macro that handles proper nesting, attribute generation, and output escaping. The macros compile down to efficient write-string and write-char calls with no runtime parsing. Multiple HTML standards are supported simultaneously through layered packages (HTML2, HTML3.2, HTML4.0, HTML5).

(html:with-html-document (:stream stream)
  (html:with-document-preamble (:stream stream)
    (html:declare-title "Example" :stream stream))
  (html:with-document-body (:stream stream)
    (html:with-section-heading ("Hello" :stream stream)
      (html:with-paragraph (:stream stream)
        (write-string "Generated by CL-HTTP." stream)))))

1.2.5 Resource Pooling

CL-HTTP uses the defresource facility for pooling frequently allocated objects: HTTP server instances, worker threads, I/O buffers, and data cache entries. Objects are allocated from the pool, used, and returned rather than freshly consed on each request. This minimizes garbage collection pressure on the hot path.

1.2.6 Condition-Based Error Handling

Errors are represented as a hierarchy of Common Lisp conditions. Network errors, HTTP status codes, authentication failures, and protocol violations each have a corresponding condition class. The condition system's restart mechanism allows fine-grained recovery: a worker thread can catch a connection-lost condition, log it, clean up resources, and return to the thread pool without crashing.

1.3 Package Architecture

CL-HTTP is organized into a layered package hierarchy. Each package has a well-defined role and a controlled set of exports that constitute its public interface.

1.3.1 Core Packages

IPC — Internal TCP Package
Low-level networking primitives: TCP sockets, stream classes, DNS resolution, byte counting, address manipulation, and character encoding macros. Defined entirely in the platform-specific tcp-stream.lisp. No portable code references IPC directly; it is used only by WWW-UTILS.
WWW-UTILS — Portability Bridge (~141 exports)
The central portability layer. Imports platform-specific symbols from the implementation's native packages (e.g., SB-THREAD, SB-MOP, SB-POSIX on SBCL; MP, SYSTEM, CLOS on LispWorks) plus IPC and RESOURCES, then re-exports a unified interface for:
URL — Uniform Resource Locators (~285 exports)
Uses WWW-UTILS. URL class hierarchy, interning, parsing, name-string generation, export type management, and search URL handling. All URL types (HTTP, HTTPS, FTP, Gopher, Mailto, News, WAIS, Telnet, RTSP) are represented as CLOS classes with a rich protocol of generic functions.
HTTP — HTTP Server (~370 exports)
Uses WWW-UTILS, URL, and HTML. The core server: request processing, header parsing and generation, content negotiation, virtual hosts, authentication realms, data caching, logging, service management, and the export-url interface. Selected symbols from WWW-UTILS are promoted into HTTP so that application code can access them as http:make-lock, http:enable-http-service, etc.

1.3.2 HTML Generation Packages

HTML generation is organized in a layered package hierarchy where each newer standard inherits from the previous one:

HTML2 — HTML 2.0 (nicknames: HTML, NETSCAPE1.0)
Base HTML generation: document structure, headings, paragraphs, lists, anchors, images, fill-out forms, and input types.
HTML3.2 (nickname: HTML3)
Tables, client-side image maps, applets, style sheets, and font control.
HTML4.0 (nickname: HTML4)
Frames, layers, object embedding, CSS integration, and accessibility attributes.
HTML5
Semantic elements, the HTML5 doctype, canvas, audio/video, and modern form input types.
XHTML1.0
XML-conformant HTML output for strict XHTML applications.

Application code typically uses HTML5 or HTML4.0, which inherit all operators from earlier standards. The Netscape extension packages (NS1.1, NS2.0, NS3.0, NS4.0) provide server push, client pull, and proprietary Netscape features.

1.3.3 Subsystem Packages

W3P — WWW Presentation System (nickname: WWW-PRESENT, ~85 exports)
Portable subset of CLIM (Common Lisp Interface Manager) for web interfaces. Provides presentation types, accept/present methods, define-presentation-type, and form-based input.
W4 — Web Walker (~32 exports)
Constraint-guided web walking. Defines activity types, constraint types, action types, and generators for declarative control of web robots.
SMTP — Simple Mail Transfer Protocol (~43 exports)
Email sending with SMTP and TLS support. Provides send-mail, send-mail-message, mailer conditions, and the with-network-mail-host macro.
LAMBDA-IR — Information Retrieval (nicknames: LR, INFORMATION-RETRIEVAL-SUBSTRATE, ~82 exports)
LambdaVista: hybrid classification and full-text retrieval. Document universes, token clusters, bit-vector indexing, and search constraints.
ST-JSON — JSON Library
JSON parsing and generation with streaming construction macros (json-object, json-array, json-key), keyword tokenization, and a JSON-escaping output stream.
MARKDOWN — Markdown to HTML Converter
Converts Markdown text to HTML using the HTML generation macros.
SCRIPT — Client-Side Scripts
JavaScript encapsulation and event handler generation.

1.3.4 Package Dependency Chain

The package dependency chain illustrates how platform-specific code is isolated from portable application code:

Implementation-Specific APIs
  (sb-thread, sb-bsd-sockets, sb-gray, sb-mop, sb-posix on SBCL)
  (mp, comm, stream, clos, system on LispWorks)
         |
         v
  IPC  (platform-specific networking)
         |
         v
  RESOURCES  (portable resource pooling)
         |
         v
  WWW-UTILS  (portability bridge)
         |
         v
  URL  (URL classes and protocols)
         |
         v
  HTML2 -> HTML3.2 -> HTML4.0 -> HTML5  (generation)
         |
         v
  HTTP  (server core, uses WWW-UTILS + URL + HTML)
    |         |          |           |
    v         v          v           v
  W3P       W4       LAMBDA-IR    SMTP
    |
    v
  Application Code

The key invariant: HTTP and all packages above it in this diagram contain no implementation-specific code. All platform dependencies flow upward through WWW-UTILS and IPC.

1.4 Directory Structure

CL-HTTP uses logical pathnames with the HTTP logical host. The table below shows the source directory layout.

Portable Source Code

ComponentLogical PathnameDescription
Serverhttp:server; Core HTTP server, URL handling, headers, HTML generation, authentication, logging
Clienthttp:client; HTTP client substrate
Proxyhttp:proxy; Caching proxy, reverse proxy, SSL proxy
W3Phttp:w3p; Presentation system
W4http:w4; Constraint-guided web walker
Lambda-IRhttp:lambda-ir; Site indexing and information retrieval
SMTPhttp:smtp; SMTP mailer
HTML Parserhttp:html-parser; Streaming HTML parser with DOM registry
LLM Interfacehttp:llm; LLM provider interface and JSON library
MCP Serverhttp:llm;mcp; Model Context Protocol server and LMACS editor
Exampleshttp:examples; Configuration examples, export definitions, client examples
FTPhttp:ftp; FTP client
CLIMhttp:clim; CLIM-based GUI interfaces
Shared Utilitieshttp:mcl;server; Portable utilities: resources, www-utils, MD5

Platform-Specific Source Code

PlatformLogical PathnameKey Files
LispWorkshttp:lw; server/, client/ — reference port
SBCLhttp:sbcl; server/, client/, llm/, proxy/, w4/, patches/
Symbolics Generahttp:lispm; server/, client/ — original implementation
CMU CLhttp:cmucl; server/
Allegro CL (OBC)http:acl;obc; server/, client/
Allegro CL (JKF)http:acl;jkf; server/
Scieneer CLhttp:scl; server/
MCLhttp:mcl; server/ — also hosts portable utilities
Lucid CLhttp:lcl; server/

Each platform-specific directory contains at minimum: package.lisp (package augmentation), tcp-stream.lisp (TCP streams and conditions), unix.lisp (threading, file ops, utilities), tcp-interface.lisp (service management and process pool), and sysdcl.lisp (system definition).

1.5 Supported Platforms

PlatformStatusNotes
LispWorksReleased Reference port. Most complete and actively maintained. Windows, Linux, macOS, UNIX. Full HTTP/1.1, SSL/TLS, proxy, client, W3P, W4, LLM/MCP.
SBCLReleased Newest full port. macOS, Linux, UNIX. Full HTTP/1.1, HTTP/2 server and client with reactor architecture, SSL/TLS via pure-tls, proxy, LLM/MCP.
Symbolics GeneraReleased Original implementation. Most sophisticated. Full HTTP/1.1, MCP server, Document Examiner integration.
CMU CLBeta UNIX. Useful reference for SBCL-family Lisps.
Allegro CLReleased Two ports: OBC (released) and JKF (beta). Windows, Linux, macOS, UNIX.
Scieneer CLBeta Linux, UNIX.
MCLReleased Macintosh Common Lisp. Hosts the portable utilities layer.
Lucid CLStale Not updated since release 58.12.

1.6 Feature Flags

CL-HTTP uses Common Lisp *features* flags to control conditional compilation of subsystems. Feature flags are pushed during pre-initialization, before any CL-HTTP code loads.

FeaturePurposeWhen Pushed
:cl-http CL-HTTP is loaded in the image Automatically, in http:server;variables
:multi-threaded The Lisp implementation supports threads Always (required for CL-HTTP)
:http-chunking Enable HTTP/1.1 chunked transfer encoding When the TCP stream implementation supports chunking
:cl-http-ssl Enable SSL/TLS server support When the SSL interface is complete
:cl-http-ssl-client Enable SSL/TLS client support When the client SSL interface is complete
:cl-http-x509 Enable X.509 certificate handling When X.509 support is available
:cl-http-file-author The platform supports file-author When POSIX file ownership is available
:w3p W3P presentation system is loaded Automatically, in http:w3p;package
:w4 W4 web walker is loaded Automatically, in http:w4;package
:lambda-ir Lambda-IR information retrieval is loaded Automatically, in http:lambda-ir;package

The recommended approach for a new port is to start with only :multi-threaded, bring up a working HTTP/1.0 server, then progressively push :http-chunking (for HTTP/1.1) and :cl-http-ssl (for HTTPS) as those subsystems are completed. Code gated by these features compiles to nothing when the feature is absent, allowing incremental bring-up.


Reference Manual | Next: Chapter 2. Installation and Configuration