thin 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of thin might be problematic. Click here for more details.
- data/CHANGELOG +4 -0
- data/lib/thin/connection.rb +15 -2
- data/lib/thin/connectors/unix_server.rb +7 -3
- data/lib/thin/version.rb +2 -2
- data/lib/thin_parser.bundle +0 -0
- data/spec/connection_spec.rb +58 -0
- data/spec/connectors/tcp_server_spec.rb +22 -0
- data/spec/connectors/unix_server_spec.rb +43 -0
- metadata +8 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 0.6.4 Sexy Lobster release
|
2
|
+
* Fix error when stopping server on UNIX domain socket, fixes #42
|
3
|
+
* Rescue errors in Connection#get_peername more gracefully, setting REMOTE_ADDR to nil, fixes #43
|
4
|
+
|
1
5
|
== 0.6.3 Ninja Cookie release
|
2
6
|
* Add tasks for Vlad the Deployer in example/vlad.rake [cnantais]
|
3
7
|
* Add Ramaze Rackup config file in example dir [tmm1]
|
data/lib/thin/connection.rb
CHANGED
@@ -11,6 +11,8 @@ module Thin
|
|
11
11
|
# Connector to the server
|
12
12
|
attr_accessor :connector
|
13
13
|
|
14
|
+
attr_accessor :request, :response
|
15
|
+
|
14
16
|
def post_init
|
15
17
|
@request = Request.new
|
16
18
|
@response = Response.new
|
@@ -53,9 +55,20 @@ module Thin
|
|
53
55
|
@connector.connection_finished(self)
|
54
56
|
end
|
55
57
|
|
58
|
+
def remote_address
|
59
|
+
@request.env[Request::FORWARDED_FOR] || (has_peername? ? socket_address : nil)
|
60
|
+
rescue
|
61
|
+
log_error($!)
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
56
65
|
protected
|
57
|
-
def
|
58
|
-
|
66
|
+
def has_peername?
|
67
|
+
!get_peername.nil? && !get_peername.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
def socket_address
|
71
|
+
Socket.unpack_sockaddr_in(get_peername)[1]
|
59
72
|
end
|
60
73
|
end
|
61
74
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Thin
|
2
2
|
module Connectors
|
3
|
-
#
|
3
|
+
# Connector to act as a UNIX domain socket server.
|
4
4
|
class UnixServer < Connector
|
5
5
|
# UNIX domain socket on which the server is listening for connections.
|
6
6
|
attr_accessor :socket
|
@@ -14,7 +14,10 @@ module Thin
|
|
14
14
|
# Connect the server
|
15
15
|
def connect
|
16
16
|
at_exit { remove_socket_file } # In case it crashes
|
17
|
-
|
17
|
+
EventMachine.start_unix_domain_server(@socket, UnixConnection, &method(:initialize_connection))
|
18
|
+
# HACK EventMachine.start_unix_domain_server doesn't return the connection signature
|
19
|
+
# so we have to go in the internal stuff to find it.
|
20
|
+
@signature = EventMachine.instance_eval{@acceptors.keys.first}
|
18
21
|
end
|
19
22
|
|
20
23
|
# Stops the server
|
@@ -38,9 +41,10 @@ module Thin
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
44
|
+
# Connection through a UNIX domain socket.
|
41
45
|
class UnixConnection < Connection
|
42
46
|
protected
|
43
|
-
def
|
47
|
+
def socket_address
|
44
48
|
# FIXME not sure about this, does it even make sense on a UNIX socket?
|
45
49
|
Socket.unpack_sockaddr_un(get_peername)
|
46
50
|
end
|
data/lib/thin/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Connection do
|
4
|
+
before do
|
5
|
+
@connection = Connection.new(mock('EM', :null_object => true))
|
6
|
+
@connection.silent = true
|
7
|
+
@connection.post_init
|
8
|
+
@connection.app = proc do |env|
|
9
|
+
[200, {}, ['']]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should parse on receive_data" do
|
14
|
+
@connection.request.should_receive(:parse).with('GET')
|
15
|
+
@connection.receive_data('GET')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should close connection on InvalidRequest error in receive_data" do
|
19
|
+
@connection.request.stub!(:parse).and_raise(InvalidRequest)
|
20
|
+
@connection.should_receive(:close_connection)
|
21
|
+
@connection.receive_data('')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should process when parsing complete" do
|
25
|
+
@connection.request.should_receive(:parse).and_return(true)
|
26
|
+
@connection.should_receive(:process)
|
27
|
+
@connection.receive_data('GET')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should process" do
|
31
|
+
@connection.process
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return HTTP_X_FORWARDED_FOR as remote_address" do
|
35
|
+
@connection.request.env['HTTP_X_FORWARDED_FOR'] = '1.2.3.4'
|
36
|
+
@connection.remote_address.should == '1.2.3.4'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return nil on error retreiving remote_address" do
|
40
|
+
@connection.stub!(:get_peername).and_raise(RuntimeError)
|
41
|
+
@connection.remote_address.should be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return nil on nil get_peername" do
|
45
|
+
@connection.stub!(:get_peername).and_return(nil)
|
46
|
+
@connection.remote_address.should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return nil on empty get_peername" do
|
50
|
+
@connection.stub!(:get_peername).and_return('')
|
51
|
+
@connection.remote_address.should be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return remote_address" do
|
55
|
+
@connection.stub!(:get_peername).and_return("\020\002?E\177\000\000\001\000\000\000\000\000\000\000\000")
|
56
|
+
@connection.remote_address.should == '127.0.0.1'
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Connectors::TcpServer do
|
4
|
+
before do
|
5
|
+
@connector = Connectors::TcpServer.new('0.0.0.0', 3333)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should connect" do
|
9
|
+
EventMachine.run do
|
10
|
+
@connector.connect
|
11
|
+
EventMachine.stop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should disconnect" do
|
16
|
+
EventMachine.run do
|
17
|
+
@connector.connect
|
18
|
+
@connector.disconnect
|
19
|
+
EventMachine.stop
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Connectors::UnixServer do
|
4
|
+
before do
|
5
|
+
@connector = Connectors::UnixServer.new('/tmp/thin-test.sock')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should connect" do
|
9
|
+
EventMachine.run do
|
10
|
+
@connector.connect
|
11
|
+
EventMachine.stop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should disconnect" do
|
16
|
+
EventMachine.run do
|
17
|
+
@connector.connect
|
18
|
+
@connector.disconnect
|
19
|
+
EventMachine.stop
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should remove socket file on close" do
|
24
|
+
@connector.close
|
25
|
+
File.exist?('/tmp/thin-test.sock').should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe UnixConnection do
|
30
|
+
before do
|
31
|
+
@connection = UnixConnection.new(nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return nil on error retreiving remote_address" do
|
35
|
+
@connection.stub!(:get_peername).and_raise(RuntimeError)
|
36
|
+
@connection.remote_address.should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return remote_address" do
|
40
|
+
@connection.stub!(:get_peername).and_return("\000\001127.0.0.1\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")
|
41
|
+
@connection.remote_address.should == '127.0.0.1'
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-Andre Cournoyer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -93,10 +93,15 @@ files:
|
|
93
93
|
- lib/thin/statuses.rb
|
94
94
|
- lib/thin/version.rb
|
95
95
|
- lib/thin.rb
|
96
|
+
- lib/thin_parser.bundle
|
96
97
|
- spec/command_spec.rb
|
97
98
|
- spec/configs
|
98
99
|
- spec/configs/cluster.yml
|
99
100
|
- spec/configs/single.yml
|
101
|
+
- spec/connection_spec.rb
|
102
|
+
- spec/connectors
|
103
|
+
- spec/connectors/tcp_server_spec.rb
|
104
|
+
- spec/connectors/unix_server_spec.rb
|
100
105
|
- spec/controllers
|
101
106
|
- spec/controllers/cluster_spec.rb
|
102
107
|
- spec/controllers/controller_spec.rb
|
@@ -126,6 +131,7 @@ files:
|
|
126
131
|
- spec/rails_app/config/initializers/mime_types.rb
|
127
132
|
- spec/rails_app/config/routes.rb
|
128
133
|
- spec/rails_app/log
|
134
|
+
- spec/rails_app/log/mongrel_debug
|
129
135
|
- spec/rails_app/public
|
130
136
|
- spec/rails_app/public/404.html
|
131
137
|
- spec/rails_app/public/422.html
|