class
Kemal::Config
- Kemal::Config
- Reference
- Object
Overview
Stores all the configuration options for a Kemal application. It's a singleton and you can access it like.
Kemal.config
Defined in:
kemal/config.crConstant Summary
-
CUSTOM_HANDLERS =
[] of Tuple(Int32 | ::Nil, HTTP::Handler) -
ERROR_HANDLERS =
{} of Int32 => (HTTP::Server::Context, Exception -> String) -
EXCEPTION_HANDLERS =
{} of Exception.class => (HTTP::Server::Context, Exception -> String) -
FILTER_HANDLERS =
[] of HTTP::Handler -
HANDLERS =
[] of HTTP::Handler -
INSTANCE =
Config.new
Constructors
Instance Method Summary
-
#add_error_handler(status_code : Int32, &handler : HTTP::Server::Context, Exception -> _)
Adds an error handler for the given HTTP status code
-
#add_exception_handler(exception : Exception.class, &handler : HTTP::Server::Context, Exception -> _)
Adds an error handler for the given exception
- #add_filter_handler(handler : HTTP::Handler)
- #add_handler(handler : HTTP::Handler, position : Int32)
- #add_handler(handler : HTTP::Handler)
- #always_rescue : Bool
- #always_rescue=(always_rescue : Bool)
- #app_name : String
- #app_name=(app_name : String)
- #clear
- #env : String
- #env=(env : String)
-
#error_handlers
Returns the defined error handlers for HTTP status codes
-
#exception_handlers
Returns the defined error handlers for exceptions
- #extra_options : OptionParser -> Nil?
- #extra_options(&extra_options : OptionParser -> )
- #extra_options=(extra_options : Nil | OptionParser -> _)
- #handlers
- #handlers=(handlers : Array(HTTP::Handler))
- #host_binding : String
- #host_binding=(host_binding : String)
-
#logger
DEPRECATED Use standard library Log
-
#logger=(logger : Kemal::BaseLogHandler)
DEPRECATED Use standard library Log
- #logging : Bool
- #logging=(logging : Bool)
- #max_multipart_form_field_size : Int32
- #max_multipart_form_field_size=(max_multipart_form_field_size : Int32)
-
#max_ranges : Int32
Maximum number of byte ranges accepted in a single
Rangerequest header. -
#max_ranges=(max_ranges : Int32)
Maximum number of byte ranges accepted in a single
Rangerequest header. - #max_request_body_size : Int32
- #max_request_body_size=(max_request_body_size : Int32)
- #max_route_cache_size : Int32
- #max_route_cache_size=(max_route_cache_size : Int32)
- #port : Int32
- #port=(port : Int32)
- #powered_by_header=(powered_by_header : Bool)
- #powered_by_header? : Bool
- #public_folder : String
- #public_folder=(public_folder : String)
- #running : Bool
- #running=(running : Bool)
- #scheme
- #serve_static : Bool | Hash(String, Bool)
- #serve_static=(serve_static : Bool | Hash(String, Bool))
- #server : HTTP::Server | Nil
- #server=(server : HTTP::Server | Nil)
- #setup
- #shutdown_message : Bool
- #shutdown_message=(shutdown_message : Bool)
- #shutdown_timeout : Time::Span
- #shutdown_timeout=(shutdown_timeout : Time::Span)
- #ssl : OpenSSL::SSL::Context::Server?
- #ssl=(ssl : Nil | OpenSSL::SSL::Context::Server)
- #static_headers : HTTP::Server::Context, String, File::Info -> | Nil
- #static_headers=(static_headers : HTTP::Server::Context, String, File::Info -> | Nil)
-
#websocket_allowed_origins : Array(String)
WebSocket Origin policy for upgrade requests.
-
#websocket_allowed_origins=(websocket_allowed_origins : Array(String))
WebSocket Origin policy for upgrade requests.
Constructor Detail
Instance Method Detail
Adds an error handler for the given HTTP status code
Adds an error handler for the given exception
Maximum number of byte ranges accepted in a single Range request header.
A Range header listing more parts than this is ignored and the full representation
is served with 200 instead. Since send_file also refuses range sets asking for
more bytes in total than the file holds, a multi-range response stays within the
file's own size plus roughly 150 bytes of multipart framing per part. Raising this
therefore raises the framing a single request can ask for; 0 ignores Range
headers entirely and advertises Accept-Ranges: none.
Without a bound, a header such as bytes=0-,0-,0-,... makes the server re-read the
whole file once per range. RFC 9110 §14.2 explicitly allows rejecting such range
sets, as they indicate "either a broken client or a deliberate denial-of-service
attack".
Maximum number of byte ranges accepted in a single Range request header.
A Range header listing more parts than this is ignored and the full representation
is served with 200 instead. Since send_file also refuses range sets asking for
more bytes in total than the file holds, a multi-range response stays within the
file's own size plus roughly 150 bytes of multipart framing per part. Raising this
therefore raises the framing a single request can ask for; 0 ignores Range
headers entirely and advertises Accept-Ranges: none.
Without a bound, a header such as bytes=0-,0-,0-,... makes the server re-read the
whole file once per range. RFC 9110 §14.2 explicitly allows rejecting such range
sets, as they indicate "either a broken client or a deliberate denial-of-service
attack".
WebSocket Origin policy for upgrade requests.
- Empty (default): same-origin —
Originmust match the requestHost(scheme is taken fromOrigin, so TLS termination in front of Kemal still works). Missing or emptyOriginis rejected with 403. - Non-empty allowlist:
Originmust match one of the entries after normalization (scheme/host/port only). MissingOriginis rejected. - Include
"*"to allow any origin, including requests withoutOrigin(previous allow-all behavior). - Use
"null"to allow the browser's opaque"null"origin.
Entries use the serialized origin form, e.g. "https://example.com" or
"http://localhost:3000".
WebSocket Origin policy for upgrade requests.
- Empty (default): same-origin —
Originmust match the requestHost(scheme is taken fromOrigin, so TLS termination in front of Kemal still works). Missing or emptyOriginis rejected with 403. - Non-empty allowlist:
Originmust match one of the entries after normalization (scheme/host/port only). MissingOriginis rejected. - Include
"*"to allow any origin, including requests withoutOrigin(previous allow-all behavior). - Use
"null"to allow the browser's opaque"null"origin.
Entries use the serialized origin form, e.g. "https://example.com" or
"http://localhost:3000".