Skip to content

Commit

Permalink
Wrap #bind_ssl in unless flag?(:without_openssl)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jul 9, 2018
1 parent b3d8a98 commit f042096
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions src/http/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -182,40 +182,42 @@ class HTTP::Server
server.local_address
end

# Creates a `OpenSSL::SSL::Server` and adds it as a socket.
#
# The SSL server wraps a `TCPServer` listenting on `host:port`.
#
# ```
# server = HTTP::Server.new { }
# context = OpenSSL::SSL::Context::Server.new
# context.certificate_chain = "openssl.crt"
# context.private_key = "openssl.key"
# server.bind_ssl "127.0.0.1", 8080, context
# ```
def bind_ssl(host : String, port : Int32, context : OpenSSL::SSL::Context::Server = OpenSSL::SSL::Context::Server.new, reuse_port : Bool = false) : Socket::IPAddress
tcp_server = TCPServer.new(host, port, reuse_port)
server = OpenSSL::SSL::Server.new(tcp_server, context)

bind(server)

tcp_server.local_address
end
{% unless flag?(:without_openssl) %}
# Creates a `OpenSSL::SSL::Server` and adds it as a socket.
#
# The SSL server wraps a `TCPServer` listenting on `host:port`.
#
# ```
# server = HTTP::Server.new { }
# context = OpenSSL::SSL::Context::Server.new
# context.certificate_chain = "openssl.crt"
# context.private_key = "openssl.key"
# server.bind_ssl "127.0.0.1", 8080, context
# ```
def bind_ssl(host : String, port : Int32, context : OpenSSL::SSL::Context::Server = OpenSSL::SSL::Context::Server.new, reuse_port : Bool = false) : Socket::IPAddress
tcp_server = TCPServer.new(host, port, reuse_port)
server = OpenSSL::SSL::Server.new(tcp_server, context)

bind(server)

tcp_server.local_address
end

# Creates a `OpenSSL::SSL::Server` and adds it as a socket.
#
# The SSL server wraps a `TCPServer` listenting on an unused port on *host*.
#
# ```
# server = HTTP::Server.new { }
# context = OpenSSL::SSL::Context::Server.new
# context.certificate_chain = "openssl.crt"
# context.private_key = "openssl.key"
# address = server.bind_ssl "127.0.0.1", context
# ```
def bind_ssl(host : String, context : OpenSSL::SSL::Context::Server = OpenSSL::SSL::Context::Server.new) : Socket::IPAddress
bind_ssl(host, 0, context)
end
# Creates a `OpenSSL::SSL::Server` and adds it as a socket.
#
# The SSL server wraps a `TCPServer` listenting on an unused port on *host*.
#
# ```
# server = HTTP::Server.new { }
# context = OpenSSL::SSL::Context::Server.new
# context.certificate_chain = "openssl.crt"
# context.private_key = "openssl.key"
# address = server.bind_ssl "127.0.0.1", context
# ```
def bind_ssl(host : String, context : OpenSSL::SSL::Context::Server = OpenSSL::SSL::Context::Server.new) : Socket::IPAddress
bind_ssl(host, 0, context)
end
{% endunless %}

This comment has been minimized.

Copy link
@Sija

Sija Jul 9, 2018

Contributor

{% end %}

This comment has been minimized.

Copy link
@asterite

asterite Jul 9, 2018

Member

Crystal Basic

This comment has been minimized.

Copy link
@straight-shoota

straight-shoota Jul 9, 2018

Author Member

It's confusing at times... Template engines of the Django family (Jinja, Liquid, Crinja) have control structures similar to Crystal macros but with explicit scope names in the end tag ({% endif %} etc.)


# Adds a `Socket::Server` *socket* to this server.
def bind(socket : Socket::Server) : Nil
Expand Down

0 comments on commit f042096

Please sign in to comment.