Reference Manual | Prev: Appendix A. Quick Reference | Next: Appendix C. Export Type Reference
CL-HTTP defines two condition hierarchies: network conditions for TCP/IP-level errors, and HTTP conditions for protocol-level status codes and server errors. Together they provide precise programmatic control over error handling in response functions, client code, and proxy operations.
Network conditions are defined in the WWW-UTILS package by the
platform-specific TCP stream implementation. They represent errors at the
transport layer and are signalled by socket operations, DNS resolution, and
connection management.
network-error (simple-error)
resolver-error
domain-resolver-error
local-network-error
unknown-host-name
unknown-address
network-resources-exhausted
network-port-in-use
remote-network-error (bad-gateway)
bad-connection-state
connection-closed
connection-lost
host-stopped-responding
connection-error
connection-refused
host-not-responding
protocol-timeout
connection-timed-out
network-error-mixin
| Condition | Description |
|---|---|
| network-error | Base class for all network-level errors. |
| resolver-error | Error during DNS name resolution. |
| domain-resolver-error | A domain name could not be resolved to an address. |
| local-network-error | An error originating from the local host's network configuration or resources. |
| unknown-host-name | The specified hostname is unknown to the DNS resolver. |
| unknown-address | The specified IP address cannot be resolved to a hostname. |
| network-resources-exhausted | Local network resources (e.g., file descriptors, sockets) are exhausted. |
| network-port-in-use | The requested port is already bound by another process. |
| remote-network-error | An error involving a remote host. Also inherits from bad-gateway
so proxy servers can report 502 status. |
| bad-connection-state | The connection is in an unexpected state. |
| connection-closed | The remote end closed the connection normally. |
| connection-lost | The connection was lost unexpectedly (reset, broken pipe). |
| host-stopped-responding | The remote host stopped responding mid-transaction. |
| connection-error | An error establishing a connection. |
| connection-refused | The remote host actively refused the connection. |
| host-not-responding | The remote host is unreachable or not responding to connection attempts. |
| protocol-timeout | A timeout expired while waiting for a protocol-level response. |
| connection-timed-out | Specialization of protocol-timeout for connection-level timeouts. |
SSL conditions are also defined in WWW-UTILS and extend
network-error. They are signalled during TLS handshake, certificate
verification, and encrypted I/O.
ssl-condition (network-error) ssl-closed (network-error) ssl-connection-closed (connection-closed) ssl-error (network-error) ssl-failure (network-error) ssl-connection-refused (connection-refused)
HTTP conditions are defined in the HTTP package in
http-conditions.lisp. They map directly to HTTP status codes and
control the server's response to clients when errors or redirections occur.
protocol-condition (condition)
http-condition
http-abort
reportable-condition
client-reportable-condition
— 4xx Client Error Conditions
server-reportable-condition
— 5xx Server Error Conditions
redirection
— 3xx Redirection Conditions
client-condition
server-condition
proxy-condition
| Code | Condition | Reason |
|---|---|---|
| 400 | bad-syntax-provided | Bad Request. The request could not be parsed or is malformed.
Subclasses: request-missing-host-header,
unknown-virtual-host,
bad-range-header-value,
bad-cookie-header-value,
bad-server-response,
bad-escaping,
request-missing-content-type-header,
ssl-not-available,
request-uri-too-long (414). |
| 401 | recoverable-unauthorized-client-access | Unauthorized. The client must provide valid credentials.
Includes :authentication-method and :authentication-realm
for the WWW-Authenticate header. Subclasses:
client-access-with-stale-nonce,
client-access-without-credentials. |
| 402 | access-requires-payment | Payment Required. |
| 403 | access-forbidden | Access Forbidden. The server refuses to fulfill the request.
Subclasses: proxy-access-forbidden,
proxy-connect-method-forbidden. |
| 404 | document-not-found | Not Found. The requested URL does not exist.
Subclasses: too-many-redirects,
document-gone (410). |
| 405 | method-not-allowed | Method Not Allowed. The HTTP method is not supported for this URL.
Subclass: connect-method-not-allowed. |
| 406 | acceptable-resource-not-found | Not Acceptable. No resource matching the client's Accept headers. |
| 407 | recoverable-unauthorized-proxy-access | Proxy Authentication Required. Subclasses:
proxy-access-with-stale-nonce,
proxy-access-without-credentials. |
| 408 | request-timeout | Request Timeout. |
| 409 | document-put-conflict | Conflict. A PUT request conflicts with the current resource state. |
| 410 | document-gone | Gone. The resource has been permanently removed. |
| 411 | content-length-required | Length Required. |
| 412 | precondition-failed | Precondition Failed. Subclass: expectation-failed (417). |
| 413 | request-entity-too-large | Request Entity Too Large. Subclass: file-upload-maximum-size-exceeded. |
| 414 | request-uri-too-long | Request URI Too Long. |
| 415 | unsupported-media-type | Unsupported Media Type. |
| 416 | invalid-range-request | Requested Range Not Valid. |
| 417 | expectation-failed | Expectation Failed. |
| 421 | misdirected-request | Misdirected Request. |
| 422 | unprocessable-content | Unprocessable Content. Syntactic or semantic error in content. |
| 426 | upgrade-required | Upgrade Required. |
| Code | Condition | Reason |
|---|---|---|
| 500 | server-internal-error | Internal Server Error. An unhandled error occurred while computing the
response. Subclasses: error-computing-response,
error-handling-post-method,
html-generation-error,
error-handling-put-method,
error-handling-delete-method. |
| 501 | server-not-implemented | Not Implemented. The server does not support the requested method.
Subclass: unsupported-method. |
| 502 | bad-gateway | Bad Gateway. The server received an invalid response from an upstream server.
Subclasses: proxy-bad-gateway,
proxy-bad-ftp-gateway,
proxy-unresolvable-domain-name,
proxy-local-network-error,
proxy-remote-network-error,
insufficient-data. |
| 503 | service-unavailable | Service Unavailable. Subclasses: server-overloaded,
proxy-service-unavailable,
proxy-connection-refused. |
| 504 | gateway-timeout | Gateway Timeout. Subclasses: client-timed-out,
proxy-connection-timeout. |
| 505 | http-version-not-supported | HTTP Version Not Supported. |
Redirection conditions are signalled to redirect the client to a different
URL. They carry a :new-urls initarg with the list of destination URLs.
| Code | Condition | Reason |
|---|---|---|
| 300 | document-multiple-choices | Multiple Choices. The resource has multiple representations. |
| 301 | document-moved-permanently | Moved Permanently. The resource has a new permanent URL. Cacheable. |
| 302 | document-found | Found. The resource is temporarily at a different URL. Cacheable. |
| 303 | document-forwarded | See Other. The response to the request can be found at another URL. Uses GET to retrieve the alternate resource. |
| 305 | document-access-via-proxy | Use Proxy. Deprecated by RFC 9110 sec 15.4.6 -- modern HTTP clients ignore it. Retained for backward compatibility only; configure proxies out-of-band (PAC, WPAD, system configuration) instead. |
| 307 | document-moved-temporarily | Temporary Redirect. Same method must be used for the redirected request. |
| 308 | document-permanent-redirect | Permanent Redirect (RFC 9110 sec 15.4.9, originally RFC 7538).
Method-preserving permanent redirect -- 308 is to 301 as 307 is to 302.
Cacheable. Used for non-safe methods (POST, PUT, DELETE, ...) on a
:permanent-redirect dispatch so the request body is not
silently dropped by legacy clients that coerce POST to GET on 301. |
The entry point http:standard-url-redirect is method-aware:
HEAD always mirrors GET (RFC 9110 sec 9.3.2). The actual condition signalled
depends on both the redirection-type argument and the HTTP
method of the request. Section references below cite RFC 9110.
| redirection-type | Method | Signal | Status |
|---|---|---|---|
:temporary-redirect |
GET / HEAD | document-found | 302 [sec 15.4.3] |
| other methods | document-moved-temporarily | 307 [sec 15.4.8] | |
:permanent-redirect |
GET / HEAD | document-moved-permanently | 301 [sec 15.4.2] |
| other methods | document-permanent-redirect | 308 [sec 15.4.9] | |
:forward |
POST | document-forwarded | 303 See Other [sec 15.4.4] |
| GET / HEAD, no explicit URL expiration | document-forwarded | 303 | |
| GET / HEAD, explicit URL expiration | document-moved-temporarily | 307 | |
| other methods (PUT, DELETE, ...) | document-moved-temporarily | 307 | |
:multiple-choices | any | document-multiple-choices | 300 [sec 15.4.1] |
:proxy | any | document-access-via-proxy | 305 (deprecated) [sec 15.4.6] |
The 307 / 308 paths preserve the request method on the retry; 301 / 302
may legacily be downgraded to GET by older user agents. The
:forward branch reflects the canonical post-redirect-get
pattern: POST -> 303 -> client GETs the Location. HTTP/1.0 clients that
do not understand 303, 307, or 308 receive a 302 downgrade via
http/1.1-redirection-downgrade-mixin; modern clients always
see the strict status code.
CL-HTTP's condition handling uses the Common Lisp restart protocol extensively. Key restarts available during HTTP request processing:
| Restart | Context | Description |
|---|---|---|
| abort | Request processing | Abort the current request and return to the process pool. |
| continue | Defconstant redefinition, generic function conflicts | Continue past benign redefinition warnings during system loading. |
Response functions can use handler-case and
handler-bind to intercept conditions and provide
application-specific recovery behavior. See also
http:debug-server
for controlling whether errors enter the interactive debugger during development.
The server's outer handler in %provide-service catches
serious-condition, not condition. Plain
warning instances signalled during a request (for example,
certificate-warning notices from pure-tls) are no longer escalated to a
500 Internal Server Error. Warnings are reported through the normal
warning machinery (typically logged), and the request continues. Code
that intentionally signals a warning from inside a response
function will not abort the response as a side effect.
To turn a warning into an error within a response function, use
(cl:error "...") or signal an instance of an
error subclass — either is caught by the outer
serious-condition handler.
When an error occurs while serving a body-bearing HTTP/1.1 request (POST, PUT, PATCH), the server must decide whether to consume the remainder of the request body so the TCP connection can be reused for the next pipelined request. CL-HTTP supports two strategies:
http:*drain-on-error-enabled-p* is NIL.
http:*drain-on-error-enabled-p* to T to enable a
phase-2 drain machinery that reads and discards the remaining request
body bytes after the error response is sent, then returns the
connection to the keep-alive pool. Default is NIL because some
upstream proxy/client combinations have proven sensitive to the drain
path and the conservative close-on-error behavior is the proven safe
choice. Enable only after testing against your specific client
population.
HTTP/2 does not require this flag: a stream-level error sends
RST_STREAM on the offending stream while the underlying
connection stays alive for other multiplexed streams.
When a condition is signalled from inside a body-consuming handler
(form parser, multipart parser, JSON post-document parser) after
the body has already been read, the drain machinery short-circuits to
"drain complete" via the per-request slot
http:server-request-body-consumed-p on
http:basic-server-mixin. Without this short-circuit a
redirect signalled from a POST form handler would cause
stream-discard-input to read further bytes from a TCP
stream that has no more body bytes, blocking the worker thread until
http:*server-timeout* expires. The slot is reset to NIL
at the start of each request by reset-transaction-state;
apply-form-response-function on
url:form-processing-mixin sets it to T just before invoking
the user response function, covering the url-encoded, multipart, and
JSON post-document paths.