Skip to content

Commit

Permalink
Move the proxy guide to root site (athena-framework/athena#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Aug 8, 2024
1 parent 31b431d commit 38cfba9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 78 deletions.
Empty file added docs/.gitkeep
Empty file.
66 changes: 0 additions & 66 deletions docs/guides/proxies.md

This file was deleted.

2 changes: 0 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ repo_url: https://github.com/athena-framework/framework

nav:
- Back to Manual: project://.
- Guides:
- Proxies & Load Balancers: guides/proxies.md
- API:
- Aliases: aliases.md
- Top Level: index.md
Expand Down
6 changes: 3 additions & 3 deletions src/bundle.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ struct Athena::Framework::Bundle < Athena::Framework::AbstractBundle

# Controls the IP addresses of trusted proxies that'll be used to get precise information about the client.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
property trusted_proxies : Array(String)? = nil

# Controls which headers your `#trusted_proxies` use.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
property trusted_headers : Athena::Framework::Request::ProxyHeader = Athena::Framework::Request::ProxyHeader[:forwarded_for, :forwarded_port, :forwarded_proto]

# Allows overriding the header name to use for a given `ATH::Request::ProxyHeader`.
#
# See the [external documentation](/Framework/guides/proxies/#custom-headers) for more information.
# See the [external documentation](/guides/proxies/#custom-headers) for more information.
property trusted_header_overrides : Hash(Athena::Framework::Request::ProxyHeader, String) = {} of NoReturn => NoReturn

# Configuration related to the `ATH::Listeners::Format` listener.
Expand Down
14 changes: 7 additions & 7 deletions src/request.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Athena::Framework::Request
# Represents the supported [Proxy Headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling#forwarding_client_information_through_proxies).
# Can be used via `ATH::Request.set_trusted_proxies` to whitelist which headers are allowed.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
@[Flags]
enum ProxyHeader
# The [`forwarded`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded) header as defined by [RFC 7239](https://datatracker.ietf.org/doc/html/rfc7239).
Expand Down Expand Up @@ -89,15 +89,15 @@ class Athena::Framework::Request
# The provided proxies are expected to be either IPv4 and/or IPv6 addresses.
# The special `"REMOTE_ADDRESS"` string is also supported that will map to the current request's remote address.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
def self.set_trusted_proxies(trusted_proxies : Enumerable(String), @@trusted_header_set : ATH::Request::ProxyHeader) : Nil
@@trusted_proxies = trusted_proxies.to_a
end

# Allows overriding the header name to look for off the request for a given `ATH::Request::ProxyHeader`.
# In some cases a proxy might not use the exact `x-forwarded-*` header name.
#
# See the [external documentation](/Framework/guides/proxies/#custom-headers) for more information.
# See the [external documentation](/guides/proxies/#custom-headers) for more information.
def self.override_trusted_header(header : ATH::Request::ProxyHeader, name : String) : Nil
@@trusted_header_overrides[header] = name
end
Expand Down Expand Up @@ -190,7 +190,7 @@ class Athena::Framework::Request
#
# Supports reading from `ATH::Request::ProxyHeader::FORWARDED_HOST`, falling back on the `"host"` header.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
def host : String?
if self.from_trusted_proxy? && (host = self.get_trusted_values(ProxyHeader::FORWARDED_HOST)) && !host.empty?
host = host.first
Expand Down Expand Up @@ -242,7 +242,7 @@ class Athena::Framework::Request
#
# Supports reading from both `ATH::Request::ProxyHeader::FORWARDED_PORT` and `ATH::Request::ProxyHeader::FORWARDED_HOST`, falling back on the `"host"` header, then `#scheme`.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
#
# ameba:disable Metrics/CyclomaticComplexity
def port : Int32
Expand Down Expand Up @@ -277,7 +277,7 @@ class Athena::Framework::Request
#
# Supports reading from `ATH::Request::ProxyHeader::FORWARDED_PROTO`.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
def secure? : Bool
if self.from_trusted_proxy? && (proto = self.get_trusted_values(ProxyHeader::FORWARDED_PROTO)) && !proto.empty?
return proto.first.downcase.in? "https", "on", "ssl", "1"
Expand All @@ -290,7 +290,7 @@ class Athena::Framework::Request

# Returns `true` if this request originated from a trusted proxy.
#
# See the [external documentation](/Framework/guides/proxies) for more information.
# See the [external documentation](/guides/proxies) for more information.
def from_trusted_proxy? : Bool
return false unless trusted_proxies = self.trusted_proxies
return false unless remote_address = self.remote_address
Expand Down

0 comments on commit 38cfba9

Please sign in to comment.