-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4da434a
commit 6b84cd1
Showing
4 changed files
with
136 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module Puma | ||
class Binding | ||
include Puma::Const | ||
extend Forwardable | ||
|
||
def initialize(io, ssl_server = nil) | ||
@io = io | ||
@ssl_server = ssl_server | ||
@path = io.path if unix? | ||
end | ||
|
||
attr_reader :io | ||
|
||
def to_s | ||
"#{protocol}://#{addrinfo_to_uri}" | ||
end | ||
|
||
def protocol | ||
if ssl? | ||
"ssl" | ||
elsif tcp? | ||
"tcp" | ||
elsif unix? | ||
"unix" | ||
end | ||
end | ||
|
||
def tcp? | ||
TCPServer === io | ||
end | ||
|
||
def ssl? | ||
defined?(MiniSSL::Server) && @ssl_server | ||
end | ||
|
||
def unix? | ||
defined?(UNIXServer) && UNIXServer === io | ||
end | ||
|
||
def unlink_fd | ||
File.unlink(@path) if File.exist?(@path) | ||
end | ||
|
||
def env | ||
if unix? | ||
{ REMOTE_ADDR => "127.0.0.1" } | ||
elsif ssl? | ||
{ HTTPS_KEY => HTTPS } | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def_delegators :@io, :close, :local_address | ||
def_delegators :@ssl_server, :no_tlsv1, :no_tlsv1_1 | ||
|
||
private | ||
|
||
def addrinfo_to_uri | ||
if local_address.ipv6? | ||
"[#{local_address.ip_address}]:#{local_address.ip_port}" | ||
elsif local_address.ipv4? | ||
local_address.ip_unpack.join(':') | ||
elsif local_address.unix? | ||
local_address.unix_path | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters