unicorn 4.3.1 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/GIT-VERSION-GEN +1 -1
  2. data/GNUmakefile +2 -29
  3. data/lib/unicorn.rb +1 -1
  4. data/lib/unicorn/const.rb +1 -1
  5. data/lib/unicorn/http_server.rb +12 -1
  6. data/lib/unicorn/socket_helper.rb +7 -7
  7. data/lib/unicorn/util.rb +1 -0
  8. data/script/isolate_for_tests +0 -18
  9. data/t/listener_names.ru +4 -0
  10. data/t/t0022-listener_names-preload_app.sh +32 -0
  11. data/test/exec/test_exec.rb +72 -86
  12. data/test/unit/test_util.rb +7 -8
  13. metadata +7 -103
  14. data/t/rails3-app/.gitignore +0 -4
  15. data/t/rails3-app/Gemfile +0 -26
  16. data/t/rails3-app/Rakefile +0 -10
  17. data/t/rails3-app/app/controllers/application_controller.rb +0 -4
  18. data/t/rails3-app/app/helpers/application_helper.rb +0 -2
  19. data/t/rails3-app/app/views/layouts/application.html.erb +0 -14
  20. data/t/rails3-app/config.ru +0 -4
  21. data/t/rails3-app/config/application.rb +0 -46
  22. data/t/rails3-app/config/boot.rb +0 -6
  23. data/t/rails3-app/config/database.yml +0 -22
  24. data/t/rails3-app/config/environment.rb +0 -5
  25. data/t/rails3-app/config/environments/development.rb +0 -19
  26. data/t/rails3-app/config/environments/production.rb +0 -42
  27. data/t/rails3-app/config/environments/test.rb +0 -32
  28. data/t/rails3-app/config/initializers/backtrace_silencers.rb +0 -7
  29. data/t/rails3-app/config/initializers/inflections.rb +0 -10
  30. data/t/rails3-app/config/initializers/mime_types.rb +0 -5
  31. data/t/rails3-app/config/initializers/secret_token.rb +0 -7
  32. data/t/rails3-app/config/initializers/session_store.rb +0 -8
  33. data/t/rails3-app/config/locales/en.yml +0 -5
  34. data/t/rails3-app/config/routes.rb +0 -58
  35. data/t/rails3-app/db/seeds.rb +0 -7
  36. data/t/rails3-app/doc/README_FOR_APP +0 -2
  37. data/t/rails3-app/lib/tasks/.gitkeep +0 -0
  38. data/t/rails3-app/public/404.html +0 -1
  39. data/t/rails3-app/public/500.html +0 -1
  40. data/t/rails3-app/public/x.txt +0 -1
  41. data/t/rails3-app/script/rails +0 -9
  42. data/t/rails3-app/test/performance/browsing_test.rb +0 -9
  43. data/t/rails3-app/test/test_helper.rb +0 -13
  44. data/t/rails3-app/vendor/plugins/.gitkeep +0 -0
  45. data/t/t0300-rails3-basic.sh +0 -28
  46. data/t/t0301-rails3-missing-config-ru.sh +0 -33
  47. data/t/t0302-rails3-alt-working_directory.sh +0 -32
  48. data/t/t0303-rails3-alt-working_directory_config.ru.sh +0 -56
  49. data/t/t0304-rails3-alt-working_directory_no_embed_cli.sh +0 -52
  50. data/t/test-rails3.sh +0 -27
  51. data/test/rails/app-1.2.3/.gitignore +0 -2
  52. data/test/rails/app-1.2.3/Rakefile +0 -7
  53. data/test/rails/app-1.2.3/app/controllers/application.rb +0 -6
  54. data/test/rails/app-1.2.3/app/controllers/foo_controller.rb +0 -36
  55. data/test/rails/app-1.2.3/app/helpers/application_helper.rb +0 -4
  56. data/test/rails/app-1.2.3/config/boot.rb +0 -11
  57. data/test/rails/app-1.2.3/config/database.yml +0 -12
  58. data/test/rails/app-1.2.3/config/environment.rb +0 -13
  59. data/test/rails/app-1.2.3/config/environments/development.rb +0 -9
  60. data/test/rails/app-1.2.3/config/environments/production.rb +0 -5
  61. data/test/rails/app-1.2.3/config/routes.rb +0 -6
  62. data/test/rails/app-1.2.3/db/.gitignore +0 -0
  63. data/test/rails/app-1.2.3/public/404.html +0 -1
  64. data/test/rails/app-1.2.3/public/500.html +0 -1
  65. data/test/rails/app-2.0.2/.gitignore +0 -2
  66. data/test/rails/app-2.0.2/Rakefile +0 -7
  67. data/test/rails/app-2.0.2/app/controllers/application.rb +0 -4
  68. data/test/rails/app-2.0.2/app/controllers/foo_controller.rb +0 -36
  69. data/test/rails/app-2.0.2/app/helpers/application_helper.rb +0 -4
  70. data/test/rails/app-2.0.2/config/boot.rb +0 -11
  71. data/test/rails/app-2.0.2/config/database.yml +0 -12
  72. data/test/rails/app-2.0.2/config/environment.rb +0 -17
  73. data/test/rails/app-2.0.2/config/environments/development.rb +0 -8
  74. data/test/rails/app-2.0.2/config/environments/production.rb +0 -5
  75. data/test/rails/app-2.0.2/config/routes.rb +0 -6
  76. data/test/rails/app-2.0.2/db/.gitignore +0 -0
  77. data/test/rails/app-2.0.2/public/404.html +0 -1
  78. data/test/rails/app-2.0.2/public/500.html +0 -1
  79. data/test/rails/app-2.1.2/.gitignore +0 -2
  80. data/test/rails/app-2.1.2/Rakefile +0 -7
  81. data/test/rails/app-2.1.2/app/controllers/application.rb +0 -4
  82. data/test/rails/app-2.1.2/app/controllers/foo_controller.rb +0 -36
  83. data/test/rails/app-2.1.2/app/helpers/application_helper.rb +0 -4
  84. data/test/rails/app-2.1.2/config/boot.rb +0 -111
  85. data/test/rails/app-2.1.2/config/database.yml +0 -12
  86. data/test/rails/app-2.1.2/config/environment.rb +0 -17
  87. data/test/rails/app-2.1.2/config/environments/development.rb +0 -7
  88. data/test/rails/app-2.1.2/config/environments/production.rb +0 -5
  89. data/test/rails/app-2.1.2/config/routes.rb +0 -6
  90. data/test/rails/app-2.1.2/db/.gitignore +0 -0
  91. data/test/rails/app-2.1.2/public/404.html +0 -1
  92. data/test/rails/app-2.1.2/public/500.html +0 -1
  93. data/test/rails/app-2.2.2/.gitignore +0 -2
  94. data/test/rails/app-2.2.2/Rakefile +0 -7
  95. data/test/rails/app-2.2.2/app/controllers/application.rb +0 -4
  96. data/test/rails/app-2.2.2/app/controllers/foo_controller.rb +0 -36
  97. data/test/rails/app-2.2.2/app/helpers/application_helper.rb +0 -4
  98. data/test/rails/app-2.2.2/config/boot.rb +0 -111
  99. data/test/rails/app-2.2.2/config/database.yml +0 -12
  100. data/test/rails/app-2.2.2/config/environment.rb +0 -17
  101. data/test/rails/app-2.2.2/config/environments/development.rb +0 -7
  102. data/test/rails/app-2.2.2/config/environments/production.rb +0 -5
  103. data/test/rails/app-2.2.2/config/routes.rb +0 -6
  104. data/test/rails/app-2.2.2/db/.gitignore +0 -0
  105. data/test/rails/app-2.2.2/public/404.html +0 -1
  106. data/test/rails/app-2.2.2/public/500.html +0 -1
  107. data/test/rails/test_rails.rb +0 -287
@@ -1,5 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- config.cache_classes = true
4
- config.action_controller.consider_all_requests_local = false
5
- config.action_controller.perform_caching = true
@@ -1,6 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- ActionController::Routing::Routes.draw do |map|
4
- map.connect ':controller/:action/:id.:format'
5
- map.connect ':controller/:action/:id'
6
- end
File without changes
@@ -1 +0,0 @@
1
- 404 Not Found
@@ -1 +0,0 @@
1
- 500 Internal Server Error
@@ -1,2 +0,0 @@
1
- /tmp
2
- /vendor
@@ -1,7 +0,0 @@
1
- require(File.join(File.dirname(__FILE__), 'config', 'boot'))
2
-
3
- require 'rake'
4
- require 'rake/testtask'
5
- require 'rake/rdoctask'
6
-
7
- require 'tasks/rails'
@@ -1,4 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- class ApplicationController < ActionController::Base
4
- end
@@ -1,36 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- require 'digest/sha1'
4
- class FooController < ApplicationController
5
- def index
6
- render :text => "FOO\n"
7
- end
8
-
9
- def xcookie
10
- cookies["foo"] = "cookie #$$"
11
- render :text => ""
12
- end
13
-
14
- def xnotice
15
- flash[:notice] = "session #$$"
16
- render :text => ""
17
- end
18
-
19
- def xpost
20
- if request.post?
21
- digest = Digest::SHA1.new
22
- out = "params: #{params.inspect}\n"
23
- if file = params[:file]
24
- loop do
25
- buf = file.read(4096) or break
26
- digest.update(buf)
27
- end
28
- out << "sha1: #{digest.to_s}\n"
29
- end
30
- headers['content-type'] = 'text/plain'
31
- render :text => out
32
- else
33
- render :status => 403, :text => "need post\n"
34
- end
35
- end
36
- end
@@ -1,4 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- module ApplicationHelper
4
- end
@@ -1,111 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- # Don't change this file!
4
- # Configure your app in config/environment.rb and config/environments/*.rb
5
-
6
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
7
-
8
- module Rails
9
- class << self
10
- def boot!
11
- unless booted?
12
- preinitialize
13
- pick_boot.run
14
- end
15
- end
16
-
17
- def booted?
18
- defined? Rails::Initializer
19
- end
20
-
21
- def pick_boot
22
- (vendor_rails? ? VendorBoot : GemBoot).new
23
- end
24
-
25
- def vendor_rails?
26
- File.exist?("#{RAILS_ROOT}/vendor/rails")
27
- end
28
-
29
- def preinitialize
30
- load(preinitializer_path) if File.exist?(preinitializer_path)
31
- end
32
-
33
- def preinitializer_path
34
- "#{RAILS_ROOT}/config/preinitializer.rb"
35
- end
36
- end
37
-
38
- class Boot
39
- def run
40
- load_initializer
41
- Rails::Initializer.run(:set_load_path)
42
- end
43
- end
44
-
45
- class VendorBoot < Boot
46
- def load_initializer
47
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
48
- Rails::Initializer.run(:install_gem_spec_stubs)
49
- end
50
- end
51
-
52
- class GemBoot < Boot
53
- def load_initializer
54
- self.class.load_rubygems
55
- load_rails_gem
56
- require 'initializer'
57
- end
58
-
59
- def load_rails_gem
60
- if version = self.class.gem_version
61
- gem 'rails', version
62
- else
63
- gem 'rails'
64
- end
65
- rescue Gem::LoadError => load_error
66
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
67
- exit 1
68
- end
69
-
70
- class << self
71
- def rubygems_version
72
- Gem::RubyGemsVersion rescue nil
73
- end
74
-
75
- def gem_version
76
- if defined? RAILS_GEM_VERSION
77
- RAILS_GEM_VERSION
78
- elsif ENV.include?('RAILS_GEM_VERSION')
79
- ENV['RAILS_GEM_VERSION']
80
- else
81
- parse_gem_version(read_environment_rb)
82
- end
83
- end
84
-
85
- def load_rubygems
86
- require 'rubygems'
87
- min_version = '1.3.1'
88
- unless rubygems_version >= min_version
89
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
90
- exit 1
91
- end
92
-
93
- rescue LoadError
94
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
95
- exit 1
96
- end
97
-
98
- def parse_gem_version(text)
99
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
100
- end
101
-
102
- private
103
- def read_environment_rb
104
- File.read("#{RAILS_ROOT}/config/environment.rb")
105
- end
106
- end
107
- end
108
- end
109
-
110
- # All that for this:
111
- Rails.boot!
@@ -1,12 +0,0 @@
1
- development:
2
- adapter: sqlite3
3
- database: db/development.sqlite3
4
- timeout: 5000
5
- test:
6
- adapter: sqlite3
7
- database: db/test.sqlite3
8
- timeout: 5000
9
- production:
10
- adapter: sqlite3
11
- database: db/production.sqlite3
12
- timeout: 5000
@@ -1,17 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- unless defined? RAILS_GEM_VERSION
4
- RAILS_GEM_VERSION = ENV['UNICORN_RAILS_VERSION']
5
- end
6
-
7
- # Bootstrap the Rails environment, frameworks, and default configuration
8
- require File.join(File.dirname(__FILE__), 'boot')
9
-
10
- Rails::Initializer.run do |config|
11
- config.frameworks -= [ :action_web_service, :action_mailer ]
12
- config.action_controller.session_store = :active_record_store
13
- config.action_controller.session = {
14
- :session_key => "_unicorn_rails_test.#{rand}",
15
- :secret => "#{rand}#{rand}#{rand}#{rand}",
16
- }
17
- end
@@ -1,7 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- config.cache_classes = false
4
- config.whiny_nils = true
5
- config.action_controller.consider_all_requests_local = true
6
- config.action_controller.perform_caching = false
7
- config.action_view.debug_rjs = true
@@ -1,5 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- config.cache_classes = true
4
- config.action_controller.consider_all_requests_local = false
5
- config.action_controller.perform_caching = true
@@ -1,6 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- ActionController::Routing::Routes.draw do |map|
4
- map.connect ':controller/:action/:id.:format'
5
- map.connect ':controller/:action/:id'
6
- end
File without changes
@@ -1 +0,0 @@
1
- 404 Not Found
@@ -1 +0,0 @@
1
- 500 Internal Server Error
@@ -1,287 +0,0 @@
1
- # -*- encoding: binary -*-
2
-
3
- # Copyright (c) 2009 Eric Wong
4
- require 'test/test_helper'
5
-
6
- # don't call exit(0) since it may be run under rake (but gmake is recommended)
7
- do_test = true
8
-
9
- $unicorn_rails_bin = ENV['UNICORN_RAILS_TEST_BIN'] || "unicorn_rails"
10
- redirect_test_io { do_test = system($unicorn_rails_bin, '-v') }
11
-
12
- unless do_test
13
- warn "#$unicorn_rails_bin not found in PATH=#{ENV['PATH']}, " \
14
- "skipping this test"
15
- end
16
-
17
- unless which('git')
18
- warn "git not found in PATH=#{ENV['PATH']}, skipping this test"
19
- do_test = false
20
- end
21
-
22
- if RAILS_GIT_REPO = ENV['RAILS_GIT_REPO']
23
- unless File.directory?(RAILS_GIT_REPO)
24
- warn "#{RAILS_GIT_REPO} not found, create it with:\n" \
25
- "\tgit clone --mirror git://github.com/rails/rails #{RAILS_GIT_REPO}" \
26
- "skipping this test for now"
27
- do_test = false
28
- end
29
- else
30
- warn "RAILS_GIT_REPO not defined, don't know where to git clone from"
31
- do_test = false
32
- end
33
-
34
- unless UNICORN_RAILS_TEST_VERSION = ENV['UNICORN_RAILS_TEST_VERSION']
35
- warn 'UNICORN_RAILS_TEST_VERSION not defined in environment, ' \
36
- 'skipping this test'
37
- do_test = false
38
- end
39
-
40
- RAILS_ROOT = "#{File.dirname(__FILE__)}/app-#{UNICORN_RAILS_TEST_VERSION}"
41
- unless File.directory?(RAILS_ROOT)
42
- warn "unsupported UNICORN_RAILS_TEST_VERSION=#{UNICORN_RAILS_TEST_VERSION}"
43
- do_test = false
44
- end
45
-
46
- ROR_V = UNICORN_RAILS_TEST_VERSION.split(/\./).map { |x| x.to_i }
47
- RB_V = RUBY_VERSION.split(/\./).map { |x| x.to_i }
48
- if RB_V[0] >= 2
49
- warn "skipping Ruby 2.0+ test with Rails <3"
50
- do_test = false
51
- elsif RB_V[0] >= 1 && RB_V[1] >= 9
52
- if RB_V[2] >= 2
53
- warn "Ruby 1.9.2+ is not compatible with Rails 2.x"
54
- do_test = false
55
- end
56
- unless ROR_V[0] >= 2 && ROR_V[1] >= 3
57
- warn "skipping Ruby >=1.9 test with Rails <2.3"
58
- do_test = false
59
- end
60
- end
61
-
62
- class RailsTest < Test::Unit::TestCase
63
- trap(:QUIT, 'IGNORE')
64
-
65
- COMMON_TMP = Tempfile.new('unicorn_tmp') unless defined?(COMMON_TMP)
66
-
67
- HEAVY_CFG = <<-EOS
68
- worker_processes 2
69
- timeout 30
70
- logger Logger.new('#{COMMON_TMP.path}')
71
- EOS
72
-
73
- def setup
74
- @pwd = Dir.pwd
75
- @tmpfile = Tempfile.new('unicorn_rails_test')
76
- @tmpdir = @tmpfile.path
77
- @tmpfile.close!
78
- assert_nothing_raised do
79
- FileUtils.cp_r(RAILS_ROOT, @tmpdir, :preserve => true)
80
- end
81
- Dir.chdir(@tmpdir)
82
- system('git', 'clone', '-nsq', RAILS_GIT_REPO, 'vendor/rails')
83
- Dir.chdir("#@tmpdir/vendor/rails") do
84
- system('git', 'reset', '-q', '--hard', "v#{UNICORN_RAILS_TEST_VERSION}")
85
- end
86
-
87
- assert(system('rake', 'db:sessions:create'))
88
- assert(system('rake', 'db:migrate'))
89
-
90
- @addr = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
91
- @port = unused_port(@addr)
92
- @start_pid = $$
93
- @pid = nil
94
- end
95
-
96
- def test_launcher
97
- tmp_dirs = %w(cache pids sessions sockets)
98
- tmp_dirs.each { |dir| assert(! File.exist?("tmp/#{dir}")) }
99
- redirect_test_io { @pid = fork { exec 'unicorn_rails', "-l#@addr:#@port" } }
100
- wait_master_ready("test_stderr.#$$.log")
101
-
102
- # basic GET
103
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo"))
104
- assert_equal "FOO\n", res.body
105
- assert_match %r{^text/html\b}, res['Content-Type']
106
- assert_equal "4", res['Content-Length']
107
- assert_equal "200 OK", res['Status']
108
-
109
- # temp dirs exist
110
- tmp_dirs.each { |dir| assert(File.directory?("tmp/#{dir}")) }
111
-
112
- # can we set cookies?
113
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo/xcookie"))
114
- assert_equal "200", res.code
115
- assert_equal "200 OK", res['Status']
116
- cookies = res.get_fields('Set-Cookie')
117
- assert_equal 2, cookies.size
118
- assert_equal 1, cookies.grep(/\A_unicorn_rails_test\./).size
119
- assert_equal 1, cookies.grep(/\Afoo=cookie/).size
120
-
121
- # how about just a session?
122
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo/xnotice"))
123
- assert_equal "200", res.code
124
- assert_equal "200 OK", res['Status']
125
- cookies = res.get_fields('Set-Cookie')
126
- assert_equal 1, cookies.size
127
- assert_equal 1, cookies.grep(/\A_unicorn_rails_test\./).size
128
-
129
- # posting forms?
130
- uri = URI.parse("http://#@addr:#@port/foo/xpost")
131
- wait_master_ready("test_stderr.#$$.log")
132
- res = Net::HTTP.post_form(uri, {"a" => "b", "c"=>"d"})
133
- assert_equal "200", res.code
134
- params = res.body.split(/\n/).grep(/^params:/)
135
- assert_equal 1, params.size
136
- params = eval(params[0].gsub!(/\Aparams:/, ''))
137
- assert_equal Hash, params.class
138
- assert_equal 'b', params['a']
139
- assert_equal 'd', params['c']
140
- assert_equal "200 OK", res['Status']
141
-
142
- # try uploading a big file
143
- tmp = Tempfile.new('random')
144
- sha1 = Digest::SHA1.new
145
- assert_nothing_raised do
146
- File.open("/dev/urandom", "rb") do |fp|
147
- 256.times do
148
- buf = fp.sysread(4096)
149
- sha1.update(buf)
150
- tmp.syswrite(buf)
151
- end
152
- end
153
- end
154
-
155
- # fixed in Rack commit 44ed4640f077504a49b7f1cabf8d6ad7a13f6441,
156
- # no released version of Rails or Rack has this fix
157
- if RB_V[0] >= 1 && RB_V[1] >= 9
158
- warn "multipart broken with Rack 1.0.0 and Rails 2.3.2.1 under 1.9"
159
- else
160
- resp = `curl -isSfN -Ffile=@#{tmp.path} http://#@addr:#@port/foo/xpost`
161
- assert $?.success?
162
- resp = resp.split(/\r?\n/)
163
- grepped = resp.grep(/^sha1: (.{40})/)
164
- assert_equal 1, grepped.size
165
- assert_equal(sha1.hexdigest, /^sha1: (.{40})/.match(grepped.first)[1])
166
-
167
- grepped = resp.grep(/^Content-Type:\s+(.+)/i)
168
- assert_equal 1, grepped.size
169
- assert_match %r{^text/plain}, grepped.first.split(/\s*:\s*/)[1]
170
- assert_equal 1, resp.grep(/^Status:/i).size
171
- end
172
-
173
- # make sure we can get 403 responses, too
174
- uri = URI.parse("http://#@addr:#@port/foo/xpost")
175
- wait_master_ready("test_stderr.#$$.log")
176
- res = Net::HTTP.get_response(uri)
177
- assert_equal "403", res.code
178
- assert_equal "403 Forbidden", res['Status']
179
-
180
- # non existent controller
181
- uri = URI.parse("http://#@addr:#@port/asdf")
182
- res = Net::HTTP.get_response(uri)
183
- assert_equal "404", res.code
184
- assert_equal "404 Not Found", res['Status']
185
-
186
- # static files
187
-
188
- # ensure file we're about to serve is not there yet
189
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/pid.txt"))
190
- assert_equal "404 Not Found", res['Status']
191
- assert_equal '404', res.code
192
-
193
- # can we serve text files based on suffix?
194
- File.open("public/pid.txt", "wb") { |fp| fp.syswrite("#$$\n") }
195
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/pid.txt"))
196
- assert_equal '200', res.code
197
- assert_equal "200 OK", res['Status']
198
- assert_match %r{^text/plain}, res['Content-Type']
199
- assert_equal "#$$\n", res.body
200
-
201
- # can we serve HTML files based on suffix?
202
- assert File.exist?("public/500.html")
203
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/500.html"))
204
- assert_equal '200', res.code
205
- assert_equal '200 OK', res['Status']
206
- assert_match %r{^text/html}, res['Content-Type']
207
- five_hundred_body = res.body
208
-
209
- # lets try pretending 500 is a controller that got cached
210
- assert ! File.exist?("public/500")
211
- assert_equal five_hundred_body, File.read("public/500.html")
212
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/500"))
213
- assert_equal '200', res.code
214
- assert_equal '200 OK', res['Status']
215
- assert_match %r{^text/html}, res['Content-Type']
216
- assert_equal five_hundred_body, res.body
217
- end
218
-
219
- def test_alt_url_root
220
- # cbf to actually work on this since I never use this feature (ewong)
221
- return unless ROR_V[0] >= 2 && ROR_V[1] >= 3
222
- redirect_test_io do
223
- @pid = fork { exec 'unicorn_rails', "-l#@addr:#@port", '-P/poo' }
224
- end
225
- wait_master_ready("test_stderr.#$$.log")
226
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/poo/foo"))
227
- # p res
228
- # p res.body
229
- # system 'cat', 'log/development.log'
230
- assert_equal "200", res.code
231
- assert_equal '200 OK', res['Status']
232
- assert_equal "FOO\n", res.body
233
- assert_match %r{^text/html\b}, res['Content-Type']
234
- assert_equal "4", res['Content-Length']
235
-
236
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo"))
237
- assert_equal "404", res.code
238
- assert_equal '404 Not Found', res['Status']
239
- end
240
-
241
- def test_alt_url_root_config_env
242
- # cbf to actually work on this since I never use this feature (ewong)
243
- return unless ROR_V[0] >= 2 && ROR_V[1] >= 3
244
- tmp = Tempfile.new('')
245
- tmp.syswrite("ENV['RAILS_RELATIVE_URL_ROOT'] = '/poo'\n")
246
- redirect_test_io do
247
- @pid = fork { exec 'unicorn_rails', "-l#@addr:#@port", "-c", tmp.path }
248
- end
249
- wait_master_ready("test_stderr.#$$.log")
250
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/poo/foo"))
251
- assert_equal "200", res.code
252
- assert_equal '200 OK', res['Status']
253
- assert_equal "FOO\n", res.body
254
- assert_match %r{^text/html\b}, res['Content-Type']
255
- assert_equal "4", res['Content-Length']
256
-
257
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo"))
258
- assert_equal "404", res.code
259
- assert_equal '404 Not Found', res['Status']
260
-
261
- res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/poo/x.txt"))
262
- assert_equal "200", res.code
263
- assert_equal "HELLO\n", res.body
264
- end
265
-
266
- def teardown
267
- return if @start_pid != $$
268
-
269
- if @pid
270
- Process.kill(:QUIT, @pid)
271
- _, status = Process.waitpid2(@pid)
272
- assert status.success?
273
- end
274
-
275
- Dir.chdir(@pwd)
276
- FileUtils.rmtree(@tmpdir)
277
- loop do
278
- Process.kill('-QUIT', 0)
279
- begin
280
- Process.waitpid(-1, Process::WNOHANG) or break
281
- rescue Errno::ECHILD
282
- break
283
- end
284
- end
285
- end
286
-
287
- end if do_test