kastner-rack 0.3.171 → 0.3.186

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,7 @@ module Rack
23
23
 
24
24
  # Return the Rack release as a dotted string.
25
25
  def self.release
26
- "0.4"
26
+ "0.4.2"
27
27
  end
28
28
 
29
29
  autoload :Builder, "rack/builder"
@@ -15,7 +15,7 @@ module Rack
15
15
  h[k] = v.to_s
16
16
  end
17
17
  end
18
- [controller.status, controller.headers, controller.body]
18
+ [controller.status, controller.headers, [controller.body.to_s]]
19
19
  end
20
20
  end
21
21
  end
@@ -47,7 +47,7 @@ module Rack
47
47
 
48
48
  def map(path, &block)
49
49
  if @ins.last.kind_of? Hash
50
- @ins.last[path] = Rack::Builder.new(&block).to_app
50
+ @ins.last[path] = self.class.new(&block).to_app
51
51
  else
52
52
  @ins << {}
53
53
  map(path, &block)
@@ -60,15 +60,19 @@ module Rack
60
60
 
61
61
  begin
62
62
  response.status = status.to_i
63
+ response.send_status(nil)
64
+
63
65
  headers.each { |k, vs|
64
66
  vs.each { |v|
65
67
  response.header[k] = v
66
68
  }
67
69
  }
70
+ response.send_header
71
+
68
72
  body.each { |part|
69
- response.body << part
73
+ response.write part
74
+ response.socket.flush
70
75
  }
71
- response.finished
72
76
  ensure
73
77
  body.close if body.respond_to? :close
74
78
  end
@@ -122,7 +122,7 @@ module Rack
122
122
 
123
123
  # The union of GET and POST data.
124
124
  def params
125
- self.GET.update(self.POST)
125
+ self.put? ? self.GET : self.GET.update(self.POST)
126
126
  rescue EOFError => e
127
127
  self.GET
128
128
  end
@@ -26,7 +26,10 @@ module Rack
26
26
  :key => 'rack.session',
27
27
  :path => '/',
28
28
  :domain => nil,
29
- :expire_after => nil
29
+ :expire_after => nil,
30
+ :secure => false,
31
+ :httponly => true,
32
+ :sidbits => 128
30
33
  }
31
34
 
32
35
  def initialize(app, options={})
@@ -50,6 +53,14 @@ module Rack
50
53
 
51
54
  private
52
55
 
56
+ # Generate a new session id using Ruby #rand. The size of the
57
+ # session id is controlled by the :sidbits option.
58
+ # Monkey patch this to use custom methods for session id generation.
59
+ def generate_sid
60
+ "%0#{@default_options[:sidbits] / 4}x" %
61
+ rand(2**@default_options[:sidbits] - 1)
62
+ end
63
+
53
64
  # Extracts the session id from provided cookies and passes it and the
54
65
  # environment to #get_session. It then sets the resulting session into
55
66
  # 'rack.session', and places options and session metadata into
@@ -110,6 +121,8 @@ module Rack
110
121
  expiry = time + options[:expire_after]
111
122
  cookie<< "; expires=#{expiry.httpdate}"
112
123
  end
124
+ cookie<< "; Secure" if options[:secure]
125
+ cookie<< "; HttpOnly" if options[:httponly]
113
126
 
114
127
  case a = (h = response[1])['Set-Cookie']
115
128
  when Array then a << cookie
@@ -45,7 +45,7 @@ module Rack
45
45
  @mutex.synchronize do
46
46
  begin
47
47
  raise RuntimeError, 'Unique id finding looping excessively' if (lc+=1) > 1000
48
- sid = "%08x" % rand(0xffffffff)
48
+ sid = generate_sid
49
49
  ret = @pool.add(sid, session)
50
50
  end until /^STORED/ =~ ret
51
51
  end
@@ -40,7 +40,7 @@ module Rack
40
40
  unless sess = @pool[sid] and ((expires = sess[:expire_at]).nil? or expires > Time.now)
41
41
  @pool.delete_if{|k,v| expiry = v[:expire_at] and expiry < Time.now }
42
42
  begin
43
- sid = "%08x" % rand(0xffffffff)
43
+ sid = generate_sid
44
44
  end while @pool.has_key?(sid)
45
45
  end
46
46
  @pool[sid] ||= {}
@@ -1,10 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = %q{rack}
3
- s.version = "0.3.171"
5
+ s.version = "0.3.186"
4
6
 
5
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
8
  s.authors = ["Christian Neukirchen"]
7
- s.date = %q{2008-11-28}
9
+ s.date = %q{2008-12-02}
8
10
  s.default_executable = %q{rackup}
9
11
  s.description = %q{Rack provides minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. Also see http://rack.rubyforge.org.}
10
12
  s.email = %q{chneukirchen@gmail.com}
@@ -15,7 +17,7 @@ Gem::Specification.new do |s|
15
17
  s.homepage = %q{http://rack.rubyforge.org}
16
18
  s.require_paths = ["lib"]
17
19
  s.rubyforge_project = %q{rack}
18
- s.rubygems_version = %q{1.2.0}
20
+ s.rubygems_version = %q{1.3.1}
19
21
  s.summary = %q{a modular Ruby webserver interface}
20
22
  s.test_files = ["test/spec_rack_auth_basic.rb", "test/spec_rack_auth_digest.rb", "test/spec_rack_auth_openid.rb", "test/spec_rack_builder.rb", "test/spec_rack_camping.rb", "test/spec_rack_cascade.rb", "test/spec_rack_cgi.rb", "test/spec_rack_commonlogger.rb", "test/spec_rack_conditionalget.rb", "test/spec_rack_deflater.rb", "test/spec_rack_directory.rb", "test/spec_rack_fastcgi.rb", "test/spec_rack_file.rb", "test/spec_rack_handler.rb", "test/spec_rack_head.rb", "test/spec_rack_lint.rb", "test/spec_rack_lobster.rb", "test/spec_rack_methodoverride.rb", "test/spec_rack_mock.rb", "test/spec_rack_mongrel.rb", "test/spec_rack_recursive.rb", "test/spec_rack_request.rb", "test/spec_rack_response.rb", "test/spec_rack_session_cookie.rb", "test/spec_rack_session_memcache.rb", "test/spec_rack_session_pool.rb", "test/spec_rack_showexceptions.rb", "test/spec_rack_showstatus.rb", "test/spec_rack_static.rb", "test/spec_rack_urlmap.rb", "test/spec_rack_utils.rb", "test/spec_rack_webrick.rb"]
21
23
 
@@ -23,9 +25,10 @@ Gem::Specification.new do |s|
23
25
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
26
  s.specification_version = 2
25
27
 
26
- if current_version >= 3 then
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
29
  else
28
30
  end
29
31
  else
30
32
  end
31
33
  end
34
+
@@ -3,7 +3,7 @@ server.document-root = "."
3
3
  server.errorlog = "lighttpd.errors"
4
4
  server.port = 9203
5
5
 
6
- server.event-handler = "freebsd-kqueue"
6
+ server.event-handler = "select"
7
7
 
8
8
  cgi.assign = ("/test" => "",
9
9
  # ".ru" => ""
@@ -5,7 +5,8 @@ require 'rack/handler/mongrel'
5
5
  require 'rack/urlmap'
6
6
  require 'rack/lint'
7
7
  require 'testrequest'
8
-
8
+ require 'timeout'
9
+
9
10
  Thread.abort_on_exception = true
10
11
  $tcp_defer_accept_opts = nil
11
12
  $tcp_cork_opts = nil
@@ -17,6 +18,8 @@ context "Rack::Handler::Mongrel" do
17
18
  server = Mongrel::HttpServer.new(@host='0.0.0.0', @port=9201)
18
19
  server.register('/test',
19
20
  Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new)))
21
+ server.register('/stream',
22
+ Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest)))
20
23
  @acc = server.run
21
24
  end
22
25
 
@@ -160,6 +163,22 @@ context "Rack::Handler::Mongrel" do
160
163
  block_ran.should.be true
161
164
  end
162
165
 
166
+ specify "should stream #each part of the response" do
167
+ body = ''
168
+ begin
169
+ Timeout.timeout(1) do
170
+ Net::HTTP.start(@host, @port) do |http|
171
+ get = Net::HTTP::Get.new('/stream')
172
+ http.request(get) do |response|
173
+ response.read_body { |part| body << part }
174
+ end
175
+ end
176
+ end
177
+ rescue Timeout::Error
178
+ end
179
+ body.should.not.be.empty
180
+ end
181
+
163
182
  teardown do
164
183
  @acc.raise Mongrel::StopServer
165
184
  end
@@ -94,7 +94,7 @@ context "Rack::Handler::WEBrick" do
94
94
  })
95
95
 
96
96
  Net::HTTP.start(@host, @port) { |http|
97
- res, body = http.get("/cookie-test")
97
+ res = http.get("/cookie-test")
98
98
  res.code.to_i.should.equal 200
99
99
  res.get_fields("set-cookie").should.equal ["one=1", "two=2"]
100
100
  }
@@ -43,3 +43,15 @@ class TestRequest
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ class StreamingRequest
48
+ def self.call(env)
49
+ [200, {"Content-Type" => "text/plain"}, new]
50
+ end
51
+
52
+ def each
53
+ yield "hello there!\n"
54
+ sleep 5
55
+ yield "that is all.\n"
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kastner-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.171
4
+ version: 0.3.186
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neukirchen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-28 00:00:00 -08:00
12
+ date: 2008-12-02 00:00:00 -08:00
13
13
  default_executable: rackup
14
14
  dependencies: []
15
15