Skip to content

Commit

Permalink
Restore #bind_ssl as deprecated api (#6551)
Browse files Browse the repository at this point in the history
* Restore #bind_ssl as deprecated api

* Add TODO remove note
  • Loading branch information
bcardiff authored and RX14 committed Aug 19, 2018
1 parent d37fdff commit 202e5ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,30 @@ module HTTP
end
end

describe "#bind_ssl" do
it "binds SSL server context" do
server = Server.new do |context|
context.response.puts "Test Server (#{context.request.headers["Host"]?})"
context.response.close
end

server_context, client_context = ssl_context_pair

socket = OpenSSL::SSL::Server.new(TCPServer.new("127.0.0.1", 0), server_context)
server.bind socket
ip_address1 = server.bind_ssl "127.0.0.1", 0, server_context
ip_address2 = socket.local_address

spawn server.listen
Fiber.yield

HTTP::Client.get("https://#{ip_address1}", tls: client_context).body.should eq "Test Server (#{ip_address1})\n"
HTTP::Client.get("https://#{ip_address2}", tls: client_context).body.should eq "Test Server (#{ip_address2})\n"

server.close
end
end

describe "#listen" do
it "fails after listen" do
server = Server.new { }
Expand Down
8 changes: 7 additions & 1 deletion src/http/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ class HTTP::Server
def bind_tls(address : Socket::IPAddress, context : OpenSSL::SSL::Context::Server) : Socket::IPAddress
bind_tls(address.address, address.port, context)
end

# DEPRECATED: Use `#bind_tls`.
# TODO: remove in 0.27.0
def bind_ssl(*args)
bind_tls(*args)
end
{% end %}

# Parses a socket configuration from *uri* and adds it to this server.
Expand Down Expand Up @@ -287,7 +293,7 @@ class HTTP::Server

bind_tls(address, context)
{% else %}
raise ArgumentError.new "Unsupported socket type: ssl (program was compiled without openssl support)"
raise ArgumentError.new "Unsupported socket type: #{uri.scheme} (program was compiled without openssl support)"
{% end %}
else
raise ArgumentError.new "Unsupported socket type: #{uri.scheme}"
Expand Down

0 comments on commit 202e5ac

Please sign in to comment.