CL-HTTP Chapter 2: Installation and Configuration


Table of Contents | Prev: Architecture | Next: Tutorial

Contents

2.1 Prerequisites
2.2 Logical Pathnames
2.3 Loading the System
2.4 Starting HTTP Service
2.5 Stopping Service
2.6 Virtual Hosts
2.7 SSL/TLS Configuration
2.8 LLM Platform Configuration
2.9 Key Configuration Variables
2.10 Platform-Specific Notes

2.1 Prerequisites

CL-HTTP requires a supported Common Lisp implementation with threading support. The following implementations have production-quality ports:

LispWorks (8.x recommended)
The reference port. Supports all features including HTTP/2, SSL/TLS, proxy, and the full client substrate on UNIX, macOS, and Windows.
SBCL (2.4+ recommended)
Full parity with the LispWorks port including HTTP/2 (reactor architecture), SSL/TLS via pure-tls, proxy server, and client. Default port: 8002.
Symbolics Genera (8.3+)
The original implementation. Full HTTP/1.1 server, client, and proxy with native network support.

Obtain the CL-HTTP source distribution and unpack it into a directory of your choice. The tree contains portable code shared by all implementations, plus per-platform subdirectories (lw/, sbcl/, lispm/, etc.) holding platform-specific files.

2.2 Logical Pathnames

CL-HTTP uses the HTTP logical host to locate all source files. This indirection allows the source tree to reside anywhere on disk while portable code references files via logical names such as "http:server;variables.lisp".

Logical pathname translations are established by loading the platform's translations.lisp file, which maps logical directories to physical paths:

Logical DirectoryContents
http:server;Portable HTTP server core
http:client;Portable HTTP client
http:proxy;Proxy server
http:mcl;server;Portable utilities (resources, www-utils, MD5)
http:w3p;W3P presentation system
http:smtp;SMTP mailer
http:examples;Configuration and example exports
http:lw;server;LispWorks platform substrate
http:sbcl;server;SBCL platform substrate

You do not normally need to edit translations. The startup script (start.lisp) loads translations automatically before any CL-HTTP code.

2.3 Loading the System

The sct-defsystem Build System

CL-HTTP uses its own system definition facility, sct-defsystem, rather than ASDF. Each subsystem (server, client, proxy, W4, etc.) has a sysdcl.lisp defining its files and load order. The system tracks file staleness and recompiles changed sources automatically. Compilation follows a strict serial order to ensure correct package and class definitions at each point.

Interactive Mode

The simplest way to load CL-HTTP is to start your Lisp and load the platform's start script. In interactive mode, the script prompts for build options:

;; LispWorks:
(load "lw/start")

;; SBCL:
(load "sbcl/start.lisp")

The script asks which subsystems to compile and load: proxy, W4 web walker, HTML parser, LLM/MCP interface, HTTP/2 support, and whether to start the server after loading. Answering with an empty line accepts the default shown in brackets.

Batch Mode

For unattended startup, pass command-line arguments to select options. In batch mode, all prompts are suppressed and defaults apply unless overridden:

# SBCL batch mode with defaults:
cd ~/git/cl-http/sbcl && sbcl --load start.lisp -- --batch

# SBCL cold compile (force recompilation of all files):
sbcl --load start.lisp -- --batch --cold-compile

# SBCL with LLM and MCP subsystems:
sbcl --load start.lisp -- --batch --llm --mcp

# LispWorks batch from shell:
lispworks -init lw/start.lisp

Common command-line flags for SBCL (placed after --):

FlagEffectDefault
--batchSuppress prompts, use defaultsoff
--cold-compileForce recompile all filesoff
--no-compileLoad only, skip compilationoff
--proxy / --no-proxyInclude proxy serveryes
--http2 / --no-http2Include HTTP/2 supportyes
--llm / --no-llmInclude LLM interfaceno
--mcp / --no-mcpInclude MCP serverno
--port NSet HTTP port8002
--configure-and-startLoad examples and start serveryes
--save-image FILESave core image after buildingoff

Cold Compilation

A cold compile deletes all FASL files and recompiles every source file from scratch. This is required after upgrading CL-HTTP, changing class definitions, or when fasl files may be stale. Once any file recompiles in the serial load list, all subsequent files are also recompiled to ensure consistent class slot layouts across compiled files.

2.4 Starting HTTP Service

After loading, start the server with http:enable-http-service:

;; Start on the standard port (default: 80, or 8000/8002 on UNIX):
(http:enable-http-service)

;; Start on a specific port:
(http:enable-http-service :on-ports 8080)

;; Start on multiple ports:
(http:enable-http-service :on-ports '(8080 8081))

This creates a listener process for each port that accepts incoming TCP connections and dispatches them to pooled worker threads.

For finer control over service parameters, use http:ensure-http-protocol-on-port directly:

(http:ensure-http-protocol-on-port 8080
  :address :all              ; listen on all interfaces
  :enable-service-p t        ; start accepting immediately
  :timeout http:*server-timeout*
  :backlog http:*connection-backlog*)

To verify which ports are active:

(http:listening-on-http-ports)    ; returns list of active ports

If the --configure-and-start option was selected during loading (the default), the start script loads http:examples;configuration.lisp and http:examples;exports.lisp, then calls http:enable-http-service automatically.

2.5 Stopping Service

;; Stop all listeners on all ports:
(http:disable-http-service)

;; Stop a specific port:
(http:disable-http-service :on-ports 8080)

;; Stop several ports:
(http:disable-http-service :on-ports '(8080 8081))

disable-http-service stops the listener processes and ceases accepting new connections. Active connections in progress are allowed to complete. The server remains loaded in the Lisp image and can be restarted at any time with enable-http-service.

2.6 Virtual Hosts

CL-HTTP supports name-based virtual hosting, allowing multiple domain names to serve different content from a single server process and IP address. Virtual hosts are dispatched using the HTTP/1.1 Host header.

;; Declare a virtual host on port 8080:
(http:add-virtual-host "www.example.com" 8080)

;; Add a nickname that maps to the same content:
(http:add-virtual-host-nick-name "example.com" 8080
  (http:local-context))

Each virtual host maintains its own URL namespace. URLs exported under one virtual host are independent of those exported under another, even when both share the same port. Export URLs for a virtual host by specifying the full host and port in the URL string:

(http:export-url #u"http://www.example.com:8080/index.html"
  :file
  :pathname "http:www;example;index.html")

Cross-Protocol Aliasing (HTTPS → HTTP)

A nick-name may target a different scheme so that an HTTPS port serves URLs exported on a plain-HTTP context. This is convenient when TLS terminates at CL-HTTP and the URL namespace itself is maintained on the HTTP side (a common LLM/MCP deployment pattern):

;; Export the MCP URL on plain HTTP:
(http:export-url #u"http://10.0.3.15:8001/cl-http/mcp-lisp.json"
  :computed
  :response-function #'mcp::mcp-respond)

;; Make the HTTPS port serve it through a nick-name alias:
(http:add-virtual-host-nick-name "10.0.3.15" 8443
  "http://10.0.3.15:8001")

The dispatch performs the cross-protocol remap once per request through a fast-path context switch — locally-serving-url-p checks the alias map independently of which port is currently listening, so URL lookups across schemes are O(1).

2.7 SSL/TLS Configuration

CL-HTTP supports HTTPS on both LispWorks (via the native comm SSL interface) and SBCL (via pure-tls, a pure Common Lisp TLS 1.3 implementation). SSL must be enabled at compile time with the :cl-http-ssl feature flag.

Enabling HTTPS

Use define-https-service or ensure-https-protocol-on-port to start an HTTPS listener. A TLS certificate and private key are required:

;; Declarative form (typically in a configuration file):
(http:define-https-service
  :port 8443
  :certificate #p"http:pw;ssl;server-cert.pem"
  :private-key #p"http:pw;ssl;server-key.pem"
  :ssl-version :tls-1.2+
  :enable-service-p t)

;; Programmatic form:
(http:ensure-https-protocol-on-port 8443
  :certificate #p"http:pw;ssl;server-cert.pem"
  :private-key #p"http:pw;ssl;server-key.pem"
  :ssl-version :tls-1.2+
  :enable-service-p t)

Certificate Types

Both PEM-encoded RSA and Ed25519 certificates are supported. The certificate and key files are specified as pathnames. For password-protected private keys, pass :password :prompt to be asked at load time, or provide the password string directly (not recommended for production).

Client Certificate Authentication

To require client certificates, set the :verify keyword:

(http:define-https-service
  :port 8443
  :certificate #p"http:pw;ssl;server-cert.pem"
  :private-key #p"http:pw;ssl;server-key.pem"
  :certificate-authorities #p"http:pw;ssl;ca-cert.pem"
  :verify :always
  :enable-service-p t)

2.8 LLM Platform Configuration

The LLM interface (http:llm;, loaded with the --llm option or the :llm loader choice) provides clients for the OpenAI, xAI, Anthropic, and Google cloud platforms, plus LM Studio and Ollama for models running locally. To configure the cloud platforms, copy http:llm;init-file-example.lisp to your home directory as cl-http-llm-init.lisp and fill in the llm:define-user-authorization forms with your API keys. The file is loaded automatically the first time a cloud LLM is accessed.

The entry points, all in the LLM package:

;; Obtain the platform client (loads the init file on first use):
(llm::current-llm :platform :anthropic)   ; :openai :xai :google :lmstudio :ollama

;; What models does the platform currently serve?
(llm:llm-available-models (llm::current-llm :platform :anthropic))

;; Chat, without and with streaming:
(llm:llm-chat llm "What is the airspeed velocity of an unladen swallow?" :max-tokens 400)
(llm:llm-chat llm prompt :stream-writer #'write-chunk)  ; writer receives each content string

;; Interactive REPL-style chat (:q exits; :mode :stream for incremental output):
(llm:llm-interactive-chat llm :mode :stream)

Default models are set by *openai-model*, *xai-model*, *anthropic-model*, and *google-model* (as of September 2026: gpt-5.5, grok-4.3, claude-sonnet-4-6, and gemini-2.5-flash). Platforms retire models regularly; when a chat that used to work starts failing, check llm-available-models and update the model. Chat history accumulates on the client object across llm-chat calls; use llm:llm-clear-history between independent conversations.

Warning — Anthropic thinking models. The Claude 5 family (claude-sonnet-5, claude-fable-5) and claude-opus-4-8 enable extended thinking by default and reject any sampling temperature other than 1.0 with 400 Bad Request. *llm-temperature* defaults to 1.0, which every platform applies when the parameter is unspecified; only lower it (globally or via :temperature) when using models that accept it, such as the Claude 4.x line. Thinking models also spend part of :max-tokens on thought before any visible output, so allow a few hundred tokens of headroom even for short replies — a budget that is too small returns a response with empty content. The same headroom advice applies to the Gemini 2.5 thinking models. Note also that gemini-3-pro-preview appears in the Google model list but is not served by the OpenAI-compatible chat endpoint this client uses.

2.9 Key Configuration Variables

These variables are normally set in http:examples;configuration.lisp or an equivalent site-specific configuration file loaded at startup. All are in the HTTP package.

Variable Default Description
*standard-http-port* 80 (UNIX: 8000 or 8002) The default port for HTTP service. Set via set-standard-http-port.
*persistent-connection-timeout* 10 (seconds) Seconds before an idle persistent connection is reaped. Controls both HTTP/1.1 keep-alive and HTTP/2 idle connections. Changes take effect immediately for HTTP/1.1 and on new connections for HTTP/2.
*server-timeout* 18000 (5 min in 60ths/sec) Idle time before the server drops a connection. Time is in 60ths of a second.
*debug-server* NIL Controls handling of internal server errors. NIL logs errors and returns a 500 response. T enters the debugger on errors (useful during development).
*log-access-log-class* common-file-log The default class for access logging. Other options include extended-common-file-log for combined-format logs.
*maximum-number-of-connections* 200 (SMP), 20 (single-core) Maximum simultaneous connections. Set via set-maximum-number-of-connections, which also adjusts reject thresholds.
*resolve-ip-addresses* T Whether to resolve IP addresses to hostnames. Set to NIL in production to avoid DNS lookup overhead.
*auto-export* :on-demand Controls automatic export of static URLs in exported directories. :on-demand exports on first access; T exports all at export time; NIL disables.

2.10 Platform-Specific Notes

LispWorks

SBCL

Symbolics Genera


Table of Contents | Prev: Architecture | Next: Tutorial