Created
June 19, 2010 01:54
-
-
Save tmm1/444476 to your computer and use it in GitHub Desktop.
basic SSL support for Thin
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
diff --git a/lib/thin/backends/base.rb b/lib/thin/backends/base.rb | |
index ee7f3e4..f22c14b 100644 | |
--- a/lib/thin/backends/base.rb | |
+++ b/lib/thin/backends/base.rb | |
@@ -27,6 +27,10 @@ module Thin | |
attr_writer :threaded | |
def threaded?; @threaded end | |
+ # Allow using SSL in the backend. | |
+ attr_writer :ssl, :ssl_options | |
+ def ssl?; @ssl end | |
+ | |
# Number of persistent connections currently opened | |
attr_accessor :persistent_connection_count | |
@@ -125,6 +129,9 @@ module Thin | |
connection.app = @server.app | |
connection.comm_inactivity_timeout = @timeout | |
connection.threaded = @threaded | |
+ if @ssl | |
+ connection.start_tls(@ssl_options) | |
+ end | |
# We control the number of persistent connections by keeping | |
# a count of the total one allowed yet. | |
diff --git a/lib/thin/server.rb b/lib/thin/server.rb | |
index 52b55ae..689c055 100644 | |
--- a/lib/thin/server.rb | |
+++ b/lib/thin/server.rb | |
@@ -82,6 +82,9 @@ module Thin | |
# Allow using threads in the backend. | |
def_delegators :backend, :threaded?, :threaded= | |
+ # Allow using SSL in the backend. | |
+ def_delegators :backend, :ssl?, :ssl=, :ssl_options= | |
+ | |
# Address and port on which the server is listening for connections. | |
def_delegators :backend, :host, :port | |
diff --git a/test.rb b/test.rb | |
new file mode 100644 | |
index 0000000..61b2977 | |
--- /dev/null | |
+++ b/test.rb | |
@@ -0,0 +1,8 @@ | |
+require 'rubygems' | |
+$:.unshift File.expand_path('../lib', __FILE__) | |
+require 'thin' | |
+ | |
+@server = Thin::Server.new('0.0.0.0', 4433, {}, proc{ [200,{},['Hello World']] }) | |
[email protected] = true | |
[email protected]_options = {:private_key_file => '/tmp/server.key', :cert_chain_file => '/tmp/server.crt'} | |
[email protected] | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment