Reference Manual | Prev: Chapter 10. HTTP Client | Next: Chapter 12. W3P Presentation System
CL-HTTP provides integrated HTTP proxy service. Proxy functionality is built into the existing server architecture, so CL-HTTP may act as a proxy without interrupting normal server operations. When CL-HTTP receives a request for a remote resource, it uses the client module to relay the information to the origin server and returns the response to the requesting client.
Three proxy modes are supported:
| File | Contents |
|---|---|
http:proxy;proxy |
Core proxy service: relay methods, reverse proxy, URL export |
http:proxy;cache |
Caching proxy: cache initialization, enable/disable, garbage collection |
http:proxy;database |
Cache database interface and file-system implementation |
http:proxy;variables |
Proxy configuration variables |
http:proxy;documentation |
Cache documentation and presentation methods |
http:proxy;utils |
Proxy utility functions |
Proxy service is enabled on a running CL-HTTP server using
http:enable-proxy-service. The proxy listens on the specified
port (or the default proxy port) and accepts requests from clients in the
allowed subnet list.
;; Enable proxy service on the default proxy port (http:enable-proxy-service) ;; Enable on a specific port (http:enable-proxy-service 8080) ;; Enable on multiple ports (http:enable-proxy-service '(8080 8081)) ;; Disable proxy service (http:disable-proxy-service) ; disable all proxy ports (http:disable-proxy-service 8080) ; disable a specific port
The proxy port can also be set at startup in the configuration file. When the HTTP server starts and proxy service ports are configured, the proxy is initialized automatically.
| Variable | Purpose |
|---|---|
http:*proxy-service* |
List of port numbers on which proxy service is active.
Set automatically by enable-proxy-service. |
http:*standard-proxy-port* |
Default port for proxy service. |
http:*proxy-caching-p* |
When non-nil, the proxy caches responses. Default is T on LispWorks, Genera, and MCL. |
http:*client-http-version* |
Controls the HTTP version used by the proxy when relaying requests to origin servers. |
The function http:initialize-proxy sets up proxy data
structures and the client substrate without enabling service. It is
called automatically from the server initialization list. Pass
T for the redo-p argument to reinitialize.
;; Reinitialize proxy structures (http:initialize-proxy t)
The caching proxy uses in-memory data structures for metadata
(resource objects, representation objects, vary dimensions) and the
file system for entity storage. Each cached response is stored as a
representation associated with a resource (identified
by the request URI). A single resource may have multiple representations
when the origin server uses Vary headers for content
negotiation.
Caching is controlled by http:*proxy-caching-p*. When
this variable is true, the proxy stores cacheable responses and serves
them on subsequent matching requests, subject to HTTP/1.1 freshness and
validation rules.
;; Enable caching (setf http:*proxy-caching-p* t) ;; Disable caching (relay-only mode) (setf http:*proxy-caching-p* nil)
The cache enforces limits on both total size and number of resources. When limits are exceeded, the least recently accessed resources are evicted.
| Variable | Purpose |
|---|---|
http:*proxy-cache-maximum-size* |
Maximum total size of cached entities in bytes. |
http:*proxy-cache-maximum-resources* |
Maximum number of cached resources. |
The caching proxy implements HTTP/1.1 cache semantics:
Expires header
or Cache-Control: max-age directive.
If-Modified-Since,
If-None-Match). A 304 (Not Modified) response refreshes the
cache entry without re-transferring the entity.
Vary headers, storing
separate representations for different values of the varying request
headers (e.g., Accept-Encoding, Accept-Language).
Cache-Control: no-store are never cached. Responses marked
no-cache are cached but always revalidated before serving.
The cache implements both incremental and full garbage collection strategies. Incremental GC runs periodically and evicts the least recently accessed resources. Full GC reclaims all expired entries and compacts the cache to stay within configured limits.
When the proxy is loaded, the cached resources can be browsed at the
URL /cl-http/proxy/resource? on the running server. Each
resource listing shows the URI, creation date, vary dimensions, total
size, and individual representations with their metadata.
The cache database is abstracted through a generic interface defined in
http:proxy;database. The default implementation uses the
local file system. Custom backends (e.g., a distributed cache backed by a
database) can be implemented by specializing the database protocol.
When a client sends an HTTP CONNECT request to the proxy, the proxy establishes a TCP tunnel to the target host and port. The client then performs a TLS handshake through the tunnel directly with the origin server. The proxy does not inspect or cache CONNECT traffic — it simply relays bytes between the client and server.
CONNECT tunneling is supported automatically when proxy service is enabled. No additional configuration is required.
A common deployment pattern uses CL-HTTP as an HTTPS front-end for HTTP back-end servers. CL-HTTP terminates the TLS connection, decrypts the request, and forwards it as plain HTTP to the back-end. Responses are encrypted and returned to the client over TLS.
This is configured using the reverse proxy (see Section 11.5) with the CL-HTTP server listening on an HTTPS port and forwarding to HTTP back-end servers.
The reverse proxy maps external URL paths to internal back-end servers. Clients connect to CL-HTTP and request URLs that appear to be local, but CL-HTTP transparently fetches the content from one or more back-end servers. This is useful for:
Reverse proxy URLs are created using http:export-url with
the :reverse-proxy export type. The
:proxy-forwardings argument specifies the back-end servers
that handle requests matching the URL prefix.
;; Map /backend/ to an internal HTTP server
(http:export-url #u"/backend/"
:reverse-proxy
:proxy-forwardings '(("internal-server.local" 8080)))
;; Map /api/ to a back-end with a specific protocol
(http:export-url #u"/api/"
:reverse-proxy
:proxy-forwardings '(("api-server.local" 9090 :http)))
;; Multiple back-end servers for load distribution
(http:export-url #u"/app/"
:reverse-proxy
:proxy-forwardings '(("app1.local" 8080)
("app2.local" 8080)))
Each entry in :proxy-forwardings is a list of
(domain-name port &optional protocol). The proxy
constructs the back-end URL by replacing the host and port portions of
the original request URL while preserving the path and query string.
A typical deployment provides HTTPS termination for an HTTP back-end:
;; Start HTTPS service on port 443
(http:enable-http-service :on-ports 443)
;; Export a reverse proxy mapping to an HTTP back-end
(http:export-url #u"/app/"
:reverse-proxy
:proxy-forwardings '(("backend.internal" 8080)))
;; Enable proxy service on the HTTPS port
(http:enable-proxy-service 443)
Clients connect via HTTPS to https://example.com/app/ and
the proxy forwards requests to http://backend.internal:8080/app/
over plain HTTP on the internal network.
The reverse proxy can translate between HTTP protocol versions in
both directions. Inbound protocol is controlled by
set-http-version (the server setting). Upstream protocol
is controlled by set-proxy-protocol-version. The
:protocol in :proxy-forwardings determines
whether HTTPS (and thus HTTP/2 ALPN negotiation) is used for the
back-end connection.
Four protocol translation modes:
| Inbound | Upstream | Use Case |
|---|---|---|
| HTTP/2 | HTTP/2 | End-to-end H2: maximum throughput with multiplexing on both sides |
| HTTP/2 | HTTP/1.1 | H2 termination: modern clients, legacy back-end |
| HTTP/1.1 | HTTP/2 | H2 uplift: multiplex legacy client requests to H2 back-end |
| HTTP/1.1 | HTTP/1.1 | Classic proxy relay |
When upstream HTTP/2 is enabled and the back-end protocol is
:https, multiple inbound requests to the same back-end
host are multiplexed through a single TLS connection via HTTP/2 stream
multiplexing. This reduces TLS handshake overhead and enables HPACK
header compression across requests.
;; End-to-end HTTP/2 (HTTPS on both sides)
(http:set-http-version :http/2) ; inbound: accept H2 clients
(http:set-proxy-protocol-version :http/2) ; upstream: use H2 to back-end
(http:export-url #u("/" :port 8443) :reverse-proxy
:proxy-forwardings '(("backend.example.com" 443 :https)))
;; H2 termination (H2 frontend, H1.1 backend)
(http:set-http-version :http/2) ; inbound: accept H2 clients
(http:set-proxy-protocol-version :http/1.1) ; upstream: H1.1 to back-end
(http:export-url #u("/" :port 8443) :reverse-proxy
:proxy-forwardings '(("backend.local" 80 :http)))
;; H2 uplift (H1.1 frontend, H2 backend with multiplexing)
(http:set-http-version :http/1.1) ; inbound: H1.1 only
(http:set-proxy-protocol-version :http/2) ; upstream: multiplex via H2
(http:export-url #u("/" :port 80) :reverse-proxy
:proxy-forwardings '(("backend.example.com" 443 :https)))
;; Classic H1.1 both sides
(http:set-http-version :http/1.1)
(http:set-proxy-protocol-version :http/1.1)
(http:export-url #u("/" :port 80) :reverse-proxy
:proxy-forwardings '(("backend.local" 80 :http)))
(http:set-http-version version)
:http/2 enables HTTP/2
via ALPN on HTTPS ports. :http/1.1 disables HTTP/2
inbound. Affects the server globally.
(http:set-proxy-protocol-version version)
:http/2 enables HTTP/2 for HTTPS upstream connections via
ALPN, with automatic fallback to HTTP/1.1. :http/1.1 or
:http/1.0 forces the respective version for all upstream
connections. Returns the previous setting.
http:*proxy-upstream-http2-enabled*
set-proxy-protocol-version.
When CL-HTTP is the origin server behind an external reverse proxy
(e.g. Caddy, nginx, HAProxy, AWS ALB), the TCP peer it sees is the
proxy — not the real client. Without intervention, the access
log, IP-based ACLs (*secure-subnets*,
*proxy-subnets*), host-log-name, and any
application code that reads (server-address *server*) all
attribute every request to the proxy's IP.
CL-HTTP recovers the real client by parsing the X-Forwarded-For
header (or RFC 7239 Forwarded) emitted by the trusted upstream
proxy, walking the chain right-to-left, and rewriting (server-address)
to the first untrusted address found. The rewrite happens once at request
intake (after headers are parsed, before dispatch), so every downstream
consumer auto-corrects. The mechanism works identically on HTTP/1.0,
HTTP/1.1, and HTTP/2.
The override is fail-closed: by default no rewrite happens. An operator must explicitly declare which upstream proxies are believed.
http:*trusted-reverse-proxies*
NIL — no rewrite ever occurs. The
declaration is independent of *read-subnets*,
*write-subnets*, and *proxy-subnets*: trusting a
host to forward client IPs does not grant it any other access right.
(http:define-trusted-reverse-proxies &rest addresses)
(http:reverse-proxy-trusts-p address)
address is in the trust
list. Accepts a 32-bit integer or a dotted-quad string. Returns NIL for
IPv6 values (via type guard) so the IPv4-only matcher is never called on
them.
http:*reverse-proxy-header*
:x-forwarded-for (default; the de facto convention),
:forwarded (RFC 7239), or :both (Forwarded takes
precedence per RFC 7239 §7.3 when both are present).
http:*reverse-proxy-max-hops*
(http:server-reverse-proxy-host server)
(http:server-reverse-proxy-forwarded-chain server)
;; CL-HTTP is fronted by Caddy at 10.0.3.10 (terminates TLS, forwards to us). ;; Trust Caddy to forward client IPs honestly. (http:define-trusted-reverse-proxies "10.0.3.10") ;; Without this declaration, CL-HTTP would log "10.0.3.10" as the client ;; for every request, regardless of the X-Forwarded-For header value.
After this single declaration, requests arriving from Caddy at
10.0.3.10 carrying X-Forwarded-For: 203.0.113.7
will have (server-address *server*) set to the integer for
203.0.113.7 before dispatch fires. The access log shows the
real client IP; ACL checks evaluate against the real client.
For each incoming request:
*trusted-reverse-proxies*, the forwarding headers are
ignored entirely. No rewrite.
X-Forwarded-For /
Forwarded per *reverse-proxy-header*;
truncate to *reverse-proxy-max-hops* entries.
*trusted-reverse-proxies*.
Return the first untrusted IPv4 address found.
"unknown" are skipped (the matcher does not yet handle
IPv6 subnet matching). If no IPv4 entry is recoverable, no rewrite.
(server-address) to the resolved
integer, clear (server-host) so downstream rendering
falls back to the address string, stash the original peer in
(server-reverse-proxy-host), store the parsed chain in
(server-reverse-proxy-forwarded-chain).
ip-subnet-match-p is
IPv4-only; IPv6 entries in the chain are passed through but cannot be
matched against the trust list or used to rewrite
(server-address).
The symmetric companion to Section 11.6: when CL-HTTP itself acts as
a proxy (forward or reverse), it can emit X-Forwarded-For,
X-Forwarded-Proto, X-Forwarded-Host, and/or
RFC 7239 Forwarded on outbound requests so that the next
hop or the origin can in turn recover the chain.
Always-on regardless of configuration: Via (RFC 9110
§7.6.3) and hop-by-hop header stripping (RFC 7230 §6.1).
http:*proxy-emit-forwarding-headers*
| Value | Headers emitted |
|---|---|
:none / nil |
(nothing extra) |
:x-forwarded (default) |
X-Forwarded-For, X-Forwarded-Proto,
X-Forwarded-Host |
:rfc-7239 |
Forwarded (RFC 7239) |
:both |
both of the above |
The IP appended to outbound headers is taken from
(http:proxy-immediate-peer-address server), which returns
(server-reverse-proxy-host server) when the inbound XFF
override (Section 11.6) has fired — that is, when CL-HTTP itself is
chained behind another trusted reverse proxy — otherwise
(server-address server). The result is that intermediate
hops are reported consistently down the chain.
The default value :x-forwarded means that any deployment
of CL-HTTP as a forward proxy will emit client IPs on every outbound
request. Operators of privacy-preserving anonymizing proxies should set
the variable to :none:
;; Suppress all X-Forwarded-* / Forwarded emission (anonymizing forward proxy) (setq http:*proxy-emit-forwarding-headers* :none) ;; Emit only the modern RFC 7239 Forwarded header (no X-Forwarded-*) (setq http:*proxy-emit-forwarding-headers* :rfc-7239) ;; Emit both X-Forwarded-* and Forwarded for maximum compatibility (setq http:*proxy-emit-forwarding-headers* :both)
The outbound XFF append honors *reverse-proxy-max-hops*
(same variable as the inbound parser) so that a hostile or buggy chain
cannot induce CL-HTTP to emit unbounded headers.
Caddy is a popular Go-based reverse proxy with automatic Let's Encrypt TLS certificate management. A common deployment pattern places Caddy on the public-facing IP (terminating TLS, holding the production cert) and forwards cleartext HTTP/1.1 to CL-HTTP on a private interface. This section gives a worked example for Genera on the VLM (Virtual Lisp Machine), the simplest configuration that exercises the full stack.
Internet LAN Genera VLM
-------- --- ----------
client -> Caddy at 10.0.3.10:447 -> CL-HTTP at 10.0.3.15:8447
(TLS) (terminates TLS) (plain HTTP/1.1)
Caddy handles certificate renewal and TLS termination. CL-HTTP runs
plain cleartext on a private port and is shielded from internet
scanners by subnet ACLs. The real client IP is recovered through
X-Forwarded-For using the override in Section 11.6.
Minimal configuration: validate with
sudo caddy validate --config /etc/caddy/Caddyfile then
start with sudo caddy start --config /etc/caddy/Caddyfile.
# cleartext on 447 gets bounced up to HTTPS on the same port
{
auto_https disable_redirects
servers 10.0.3.10:447 {
listener_wrappers {
http_redirect
tls
}
}
}
# External TLS listener; proxies cleartext HTTP/1.1 to the backend
https://www.symbolics.biz:447 {
bind 10.0.3.10
tls /etc/letsencrypt/live/www.symbolics.biz/fullchain.pem \
/etc/letsencrypt/live/www.symbolics.biz/privkey.pem
reverse_proxy 10.0.3.15:8447 {
transport http {
versions 1.1
}
}
}
Caddy automatically emits X-Forwarded-For,
X-Forwarded-Proto, and X-Forwarded-Host on every
forwarded request. The versions 1.1 directive pins HTTP/1.1
upstream because Genera's CL-HTTP does not yet support inbound HTTP/2;
omit it on platforms (LispWorks, SBCL) where HTTP/2 is available and
desired upstream.
One line declares Caddy trusted; one line enables service on the
private HTTPS port (cleartext locally, since Caddy holds the TLS context).
Place these in your site's configuration.lisp:
;; Trust Caddy at 10.0.3.10 to forward client IPs. Without this ;; declaration, the access log would record "10.0.3.10" as the client ;; for every request, regardless of X-Forwarded-For. (http:define-trusted-reverse-proxies "10.0.3.10") ;; Restrict reads/writes to LAN subnets (and your VPN range) so external ;; scanners that bypass Caddy and connect directly to 8447 are rejected. (http:define-read-subnets "10.0.3.0" "10.0.5.0" "73.234.113.27") (http:define-write-subnets "10.0.3.0" "10.0.5.0" "73.234.113.27") ;; Enable the backend port (http:enable-http-service :on-ports '(8447 8001))
Public URLs (https://www.symbolics.biz:447/...) and the
internal URLs CL-HTTP exports (http://www.symbolics.biz:8447/...)
use different schemes and ports. Three pieces of configuration bridge
the two contexts so requests dispatch correctly and generated links
point clients back through Caddy rather than at the internal port.
;; Site parameters (mirror these to match your Caddyfile)
(defparameter *symbolics-host* "www.symbolics.biz")
(defparameter *symbolics-external-port* 447) ; Caddy public
(defparameter *symbolics-internal-port* 8447) ; CL-HTTP backend
(defparameter *symbolics-external-protocol* :https)
;; Generate relative URLs so cross-context remapping can rewrite them.
;; Absolute URLs in responses would otherwise carry the internal port.
(setq url:*relativize-urls* t)
;; Tell the URL interner that requests arriving at the external host:port
;; match URLs exported under the internal http://host:port context.
(http:add-virtual-host-nick-name
*symbolics-host* *symbolics-external-port*
(http:local-port-context *symbolics-internal-port* :http))
;; Rewrite absolute internal URLs back to the external form whenever they
;; appear in outbound responses (Location, Content-Location, redirects,
;; generated link href values, etc.).
(http:define-url-context-remappings
`((:http ,*symbolics-host* ,*symbolics-internal-port*
,*symbolics-host* ,*symbolics-external-port* ,*symbolics-external-protocol*)))
After loading this configuration the virtual-host table shows:
;; Virtual Host Mappings (host:port => Local-Context) ;; www.symbolics.biz:447 => http://www.symbolics.biz:8447 ;; URL Context Remappings (external internal) ;; https://www.symbolics.biz:447 => http://www.symbolics.biz:8447
Use http:show-virtual-hosts and
http:show-url-context-remapping to inspect the current
configuration; http:clear-virtual-hosts and
http:clear-url-context-remapping reset them.
url:*relativize-urls*
:8447 to the client.
(http:add-virtual-host-nick-name host port local-context)
host:port as a nickname for
local-context (built via
http:local-port-context). Incoming requests carrying that
Host header are interned against the local context, so URLs
exported on the internal port match requests arriving on the external
port.
(http:define-url-context-remappings &rest mappings)
(internal-protocol internal-host internal-port
external-host external-port external-protocol).
At response-generation time, internal URLs that match the inside of a
mapping are rewritten to the outside form.
http:show-virtual-hosts,
http:clear-virtual-hosts
http:show-url-context-remapping,
http:clear-url-context-remapping
Without this configuration, a request for
https://www.symbolics.biz:447/foo arrives at CL-HTTP, the
URL interner fails to match an export under
http://www.symbolics.biz:8447/foo, and a 404 is returned.
Generated links would also point at the internal port, breaking
navigation.
https://www.symbolics.biz:447/ with
a valid TLS cert.
X-Forwarded-For).
(http:host-log-name *server*) and any application code
reading (server-address *server*) see the real client.
Internal clients reaching the public hostname via the router's
hairpin NAT appear as the router's internal address (e.g.
10.0.3.1) rather than their actual LAN address. This is a
network-topology artifact: the router rewrites the source IP before the
packet reaches Caddy, so Caddy has no way to know the original LAN
client. If precise LAN-client identification is required, either:
10.0.3.15)
directly — internal clients bypass Caddy and CL-HTTP sees the LAN
peer's real IP (no override fires; peer is not in the trust list).
Proxy access is controlled by subnet filtering. Only clients whose IP addresses match the allowed subnets may use the proxy. Two variables govern access:
| Variable | Purpose |
|---|---|
http:*proxy-subnets* |
List of subnet specifications allowed to use the proxy. When
nil, falls back to http:*secure-subnets*. |
http:*secure-subnets* |
Global secure subnet list shared with the server. Used as
fallback when *proxy-subnets* is nil. |
http:*disallowed-subnets* |
Subnets explicitly denied proxy access, overriding the allow lists. |
;; Allow only the local network to use the proxy
(setf http:*proxy-subnets*
(list (http:parse-internet-addresses "192.168.1.0" "255.255.255.0")))
;; Deny a specific host
(setf http:*disallowed-subnets*
(list (http:parse-internet-addresses "192.168.1.100" "255.255.255.255")))
When a client outside the allowed subnets attempts to use the proxy,
a proxy-access-forbidden condition is signalled and the
client receives a 403 (Forbidden) response.
The proxy supports HTTP Proxy-Authenticate / Proxy-Authorization header exchanges. When proxy authentication is enabled, clients must supply valid credentials before the proxy will relay their requests. Authentication operates independently of origin-server authentication — both can be required for the same request.
Subnet restrictions and proxy authentication can be combined for defense in depth. A typical configuration restricts proxy access to the local network via subnets and additionally requires authentication for sensitive destinations.
;; Configure proxy access control
(setf http:*proxy-subnets*
(list (http:parse-internet-addresses "10.0.0.0" "255.0.0.0")))
;; Enable proxy service with authentication
(http:enable-proxy-service 8080)
The CL-HTTP proxy is designed as a platform for intelligent caching and collaboration research. Several extension opportunities exist:
http:proxy;examples;prefetch.lisp.
Reference Manual | Prev: Chapter 10. HTTP Client | Next: Chapter 12. W3P Presentation System