unicorn-simon 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/unicorn/http_request.rb +31 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8233befe487ff25246272c73d770f44c5949e018
4
- data.tar.gz: aa6d378ca633852e97c9f96429bb56cdab638ca8
3
+ metadata.gz: fabe2ee1dc0ca2d385eacce6b3e06b85d028ab78
4
+ data.tar.gz: 5c3a0278f09b24227219afba7d5ecd1d478639ca
5
5
  SHA512:
6
- metadata.gz: 92eb896198b0c0b77d7c7c668aba1e61b2149e5d7d69f61bb371f7a2b8ddcf990c43f26ca1353c81f2f03e7f76d1d336b0c7e037a5fd120684e3b6b579c1ab3f
7
- data.tar.gz: af4a1c80b5be6e12ee7498acd280d575e6cc47e61d6d89878d860e19e18683cd74e8d4f40b12efd759e24fed5a543b242442fc5114473aafa82bc878d9da8ade
6
+ metadata.gz: f966aa43e2c30d2e0ccfa3932708e7fa63f5279dfa66fbcd4dbadc81d3f4851b7474a2074c9604bd84f85ff801657e0354fc11c9b586ebc4cdd09b7a8c93dd46
7
+ data.tar.gz: 16eb0a564dd6acd3e1b452f18a1e3e141789069348cf19a4ce18f9b6ad95c5514bf1f64572601cc90ad58fb2ca94e156efa1850c849ebdf48018f3d69b1b8196
@@ -29,9 +29,9 @@ class Unicorn::HttpParser
29
29
  # 2.2+ optimizes hash assignments when used with literal string keys
30
30
  HTTP_RESPONSE_START = [ 'HTTP', '/1.1 ']
31
31
  @@input_class = Unicorn::TeeInput
32
+ @@raindrops_tcp_info_defined = defined?(Raindrops::TCP_Info)
32
33
  @@check_client_connection = false
33
34
 
34
- # TCP_TIME_WAIT: 6, TCP_CLOSE: 7, TCP_CLOSE_WAIT: 8, TCP_LAST_ACK: 9
35
35
  IGNORED_CHECK_CLIENT_SOCKET_STATES = (6..9)
36
36
 
37
37
  def self.input_class
@@ -87,18 +87,7 @@ def read(socket)
87
87
  end
88
88
 
89
89
  # detect if the socket is valid by checking client connection.
90
- if @@check_client_connection
91
- if defined?(Raindrops::TCP_Info)
92
- tcp_info = Raindrops::TCP_Info.new(socket)
93
- if IGNORED_CHECK_CLIENT_SOCKET_STATES.cover?(tcp_info.state)
94
- socket.close
95
- raise Errno::EPIPE
96
- end
97
- elsif headers?
98
- self.response_start_sent = true
99
- HTTP_RESPONSE_START.each { |c| socket.write(c) }
100
- end
101
- end
90
+ check_client_connection(socket) if @@check_client_connection
102
91
 
103
92
  e['rack.input'] = 0 == content_length ?
104
93
  NULL_IO : @@input_class.new(socket, self)
@@ -119,4 +108,33 @@ def call
119
108
  def hijacked?
120
109
  env.include?('rack.hijack_io'.freeze)
121
110
  end
111
+
112
+ private
113
+
114
+ def check_client_connection(socket)
115
+ if @@raindrops_tcp_info_defined && TCPSocket === socket
116
+ tcp_info = Raindrops::TCP_Info.new(socket)
117
+ raise Errno::EPIPE, "client closed connection".freeze, [] if closed_state?(tcp_info.state)
118
+ elsif headers?
119
+ self.response_start_sent = true
120
+ HTTP_RESPONSE_START.each { |c| socket.write(c) }
121
+ end
122
+ end
123
+
124
+ def closed_state?(state)
125
+ case state
126
+ when 6 # TCP_TIME_WAIT
127
+ true
128
+ when 7 # TCP_CLOSE
129
+ true
130
+ when 8 # TCP_CLOSE_WAIT
131
+ true
132
+ when 9 # TCP_LAST_ACK
133
+ true
134
+ when 11 # TCP_CLOSING
135
+ true
136
+ else
137
+ false
138
+ end
139
+ end
122
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicorn-simon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - unicorn hackers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-25 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack