Skip to content
This repository

passing additional options in thin handler #439

Closed
wants to merge 2 commits into from

2 participants

Kacper Cieśla James Tucker
Kacper Cieśla

Rack::Handler::Thin.run takes hash as an argument, but it only makes use of :Host and :Port options. Thin::Server.new however also supports options like :signals and :tag ( https://github.com/macournoyer/thin/blob/master/lib/thin/server.rb#L97 ) So it could be nice if these options also were passed.

First commit takes care of the above, and optional second commit is for unlikely case of people still using thin below version 0.8 (5 years old) that doesn't support passing additional options.

James Tucker
Owner

I cherry-picked these and then fixed the race conditions introduced in 00f9fc1

Thanks.

James Tucker raggi closed this
Kacper Cieśla

Was there any? If yes, I'm sorry, I thought first first thread was always dead when second one is started. And I wasn't sure I can add :tag option to other tests.

Anyway, thanks for merging and fixing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 22 additions and 3 deletions. Show diff stats Hide diff stats

  1. +6 3 lib/rack/handler/thin.rb
  2. +16 0 test/spec_thin.rb
9 lib/rack/handler/thin.rb
@@ -6,9 +6,12 @@ module Rack
6 6 module Handler
7 7 class Thin
8 8 def self.run(app, options={})
9   - server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
10   - options[:Port] || 8080,
11   - app)
  9 + host = options.delete(:Host) || '0.0.0.0'
  10 + port = options.delete(:Port) || 8080
  11 + args = [host, port, app, options]
  12 + # Thin versions below 0.8.0 do not support additional options
  13 + args.pop if ::Thin::VERSION::MAJOR < 1 && ::Thin::VERSION::MINOR < 8
  14 + server = ::Thin::Server.new(*args)
12 15 yield server if block_given?
13 16 server.start
14 17 end
16 test/spec_thin.rb
@@ -79,6 +79,22 @@
79 79
80 80 @server.stop!
81 81 @thread.kill
  82 +
  83 + # Passing additional options to thin
  84 +
  85 + @thread = Thread.new do
  86 + Rack::Handler::Thin.run(@app, :Host => @host='127.0.0.1', :Port => @port=9204, :tag => 'foo') do |server|
  87 + @server = server
  88 + end
  89 + end
  90 +
  91 + should "set tag for server" do
  92 + @server.tag.should.equal 'foo'
  93 + end
  94 +
  95 + @server.stop!
  96 + @thread.kill
  97 +
82 98 end
83 99
84 100 rescue LoadError

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.