class Puma::DSL
def set_remote_address(val=:socket)
set_remote_address :localhost
@example
The default is +:socket+.
entirely in your hands.
you wish. Because Puma never uses this field anyway, it's format is
5. **\
protocol attached to it, will fall back to :socket
HAproxy PROXY protocol, version 1. If the request does not have the PROXY
4. **proxy_protocol: :v1**- set the remote address to the value read from the
Puma will fall back to the behavior of :socket
headers such as X-Forwarded-For to be used as well. If this header is absent,
Only the first word (as separated by spaces or comma) is used, allowing
`set_remote_address header: "X-Real-IP"`.
provided http header. For instance:
3. **header:
2. **:localhost** - set the remote address to "127.0.0.1"
system call), Puma will return "0.0.0.0"
if the peer disconnects between the connection being accepted and the getpeername
syscall. This is the normal behavior. If this fails for any reason (e.g.,
1. **:socket** - read the peername from the socket using the
There are 5 possible values:
slows down the handling significantly.
a kernel syscall is required which for very fast rack handlers
is configurable because to calculate the true socket peer address
Control how the remote address of the connection is set. This
def set_remote_address(val=:socket) case val when :socket @options[:remote_address] = val when :localhost @options[:remote_address] = :value @options[:remote_address_value] = "127.0.0.1".freeze when String @options[:remote_address] = :value @options[:remote_address_value] = val when Hash if hdr = val[:header] @options[:remote_address] = :header @options[:remote_address_header] = "HTTP_" + hdr.upcase.tr("-", "_") elsif protocol_version = val[:proxy_protocol] @options[:remote_address] = :proxy_protocol protocol_version = protocol_version.downcase.to_sym unless [:v1].include?(protocol_version) raise "Invalid value for proxy_protocol - #{protocol_version.inspect}" end @options[:remote_address_proxy_protocol] = protocol_version else raise "Invalid value for set_remote_address - #{val.inspect}" end else raise "Invalid value for set_remote_address - #{val}" end end