module
Amber::Router::RequestScheme
Overview
Decides which scheme, "https" or "http", a client used to reach the
application. HTTP::Request#scheme and HTTP::Request#https? call it,
and everything in Amber that asks "is this request HTTPS" (the cookie
jar's Secure handling, and with it the session and CSRF cookies) goes
through those two methods.
The scheme starts as the connection's own: "https" when Amber terminates
TLS itself (server.ssl is configured), otherwise "http". When the
immediate peer is a trusted proxy, the scheme that proxy reported
replaces it. Amber reads only the header family the trusted proxies write
(server.trusted_proxy_headers), because a proxy passes the other family
through from the client unchanged:
"x-forwarded"(the default): the last value ofX-Forwarded-Proto."forwarded": theproto=parameter of the lastForwardedelement (RFC 7239).
Each proxy appends its own value to the end of these headers, so the last
one is the value the trusted hop wrote; anything to its left came from
further away and is not trusted. A value other than http or https, or no
header at all, keeps the connection's scheme. Other headers, such as the
CGI-style HTTPS: on, are never read: a proxy passes them through from
the client unchanged. A request whose peer is not a trusted proxy keeps
its real scheme whatever headers it carries.
Defined in:
amber/router/request_scheme.crConstant Summary
-
HTTP =
"http" -
HTTPS =
"https"
Class Method Summary
-
.resolve(request : ::HTTP::Request, trusted_proxies : Amber::Support::TrustedProxies, server_terminates_tls : Bool) : String
Returns the scheme of request.
Class Method Detail
Returns the scheme of request. trusted_proxies comes from the
server.trusted_proxies and server.trusted_proxy_headers settings,
and server_terminates_tls states whether Amber itself accepted the
connection over TLS.