jaws 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/jaws/server.rb +31 -10
  3. data/spec/spec_helper.rb +1 -0
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -64,7 +64,7 @@ module Jaws
64
64
  # Initializes a new Jaws server object. Pass it a hash of options (:Host, :Port, :MaxClients, and :SystemCores valid)
65
65
  def initialize(options = DefaultOptions)
66
66
  @options = DefaultOptions.merge(options)
67
- self.class::DefaultOptions.each do |k,v|
67
+ DefaultOptions.each do |k,v|
68
68
  send(:"#{Jaws.decapse_name(k.to_s)}=", @options[k])
69
69
  end
70
70
  self.extend Mutex_m
@@ -156,6 +156,14 @@ module Jaws
156
156
  else
157
157
  headers.delete("Content-Length")
158
158
  end
159
+
160
+ if (req.version[0] <= 1 && req.version[1] < 1) #old http versions
161
+ if (!body_len) # with no pre-defined length
162
+ headers.delete("Transfer-Encoding")
163
+ headers["Connection"] = "close"
164
+ # become connection-close with a transfer-encoding of identity
165
+ end
166
+ end
159
167
 
160
168
  headers.each do |key, vals|
161
169
  vals.each_line do |val|
@@ -165,6 +173,13 @@ module Jaws
165
173
  response << "\r\n"
166
174
 
167
175
  client.write(response)
176
+
177
+ connection_should_close = false
178
+ if ((req.headers["CONNECTION"] && req.headers["CONNECTION"] =~ /close/) ||
179
+ (headers["Connection"] && headers["Connection"] =~ /close/) ||
180
+ (req.version == [1,0] && req.headers["CONNECTION"] !~ /keep-alive/))
181
+ connection_should_close = true
182
+ end
168
183
 
169
184
  # only output a body if the request wants one and the status code
170
185
  # should have one.
@@ -188,21 +203,27 @@ module Jaws
188
203
  return
189
204
  end
190
205
  else
191
- # If the app didn't set a length, we do it chunked.
192
- body.each do |chunk|
193
- client.write(chunk.size.to_s(16) + "\r\n")
194
- client.write(chunk)
206
+ # If the app didn't set a length, we need to send the data
207
+ # in a way the client will understand. That means, for http<1.1
208
+ # we close the connection. For http>1.0 we do chunked.
209
+ if (connection_should_close && headers["Content-Encoding"] != 'chunked')
210
+ body.each do |chunk|
211
+ client.write(chunk)
212
+ end
213
+ else
214
+ body.each do |chunk|
215
+ client.write(chunk.size.to_s(16) + "\r\n")
216
+ client.write(chunk)
217
+ client.write("\r\n")
218
+ end
219
+ client.write("0\r\n")
195
220
  client.write("\r\n")
196
221
  end
197
- client.write("0\r\n")
198
- client.write("\r\n")
199
222
  end
200
223
  end
201
224
 
202
225
  # if the conditions are right, close the connection
203
- if ((req.headers["CONNECTION"] && req.headers["CONNECTION"] =~ /close/) ||
204
- (headers["Connection"] && headers["Connection"] =~ /close/) ||
205
- (req.version == [1,0]))
226
+ if (connection_should_close)
206
227
  client.close_write
207
228
  end
208
229
  rescue Errno::EPIPE
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  require 'spec'
4
5
  require 'spec/autorun'
5
6
  require 'yaml'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Graham Batty
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-16 00:00:00 -06:00
17
+ date: 2010-03-17 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency