rack 2.2.9 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +138 -101
  3. data/CONTRIBUTING.md +53 -47
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +287 -0
  6. data/Rakefile +40 -7
  7. data/SPEC.rdoc +166 -125
  8. data/contrib/LICENSE.md +7 -0
  9. data/contrib/logo.webp +0 -0
  10. data/lib/rack/auth/abstract/handler.rb +3 -1
  11. data/lib/rack/auth/abstract/request.rb +3 -1
  12. data/lib/rack/auth/digest/md5.rb +1 -131
  13. data/lib/rack/auth/digest/nonce.rb +1 -54
  14. data/lib/rack/auth/digest/params.rb +1 -54
  15. data/lib/rack/auth/digest/request.rb +1 -43
  16. data/lib/rack/auth/digest.rb +256 -0
  17. data/lib/rack/body_proxy.rb +3 -1
  18. data/lib/rack/builder.rb +60 -42
  19. data/lib/rack/cascade.rb +2 -0
  20. data/lib/rack/chunked.rb +16 -13
  21. data/lib/rack/common_logger.rb +23 -18
  22. data/lib/rack/conditional_get.rb +18 -15
  23. data/lib/rack/constants.rb +62 -0
  24. data/lib/rack/content_length.rb +12 -16
  25. data/lib/rack/content_type.rb +8 -5
  26. data/lib/rack/deflater.rb +40 -26
  27. data/lib/rack/directory.rb +9 -3
  28. data/lib/rack/etag.rb +14 -23
  29. data/lib/rack/events.rb +4 -0
  30. data/lib/rack/file.rb +2 -0
  31. data/lib/rack/files.rb +15 -17
  32. data/lib/rack/head.rb +9 -8
  33. data/lib/rack/headers.rb +154 -0
  34. data/lib/rack/lint.rb +740 -649
  35. data/lib/rack/lock.rb +2 -5
  36. data/lib/rack/logger.rb +2 -0
  37. data/lib/rack/media_type.rb +4 -9
  38. data/lib/rack/method_override.rb +5 -1
  39. data/lib/rack/mime.rb +8 -0
  40. data/lib/rack/mock.rb +1 -271
  41. data/lib/rack/mock_request.rb +166 -0
  42. data/lib/rack/mock_response.rb +124 -0
  43. data/lib/rack/multipart/generator.rb +7 -5
  44. data/lib/rack/multipart/parser.rb +123 -85
  45. data/lib/rack/multipart/uploaded_file.rb +4 -0
  46. data/lib/rack/multipart.rb +20 -40
  47. data/lib/rack/null_logger.rb +9 -0
  48. data/lib/rack/query_parser.rb +76 -44
  49. data/lib/rack/recursive.rb +2 -0
  50. data/lib/rack/reloader.rb +0 -2
  51. data/lib/rack/request.rb +189 -91
  52. data/lib/rack/response.rb +131 -61
  53. data/lib/rack/rewindable_input.rb +24 -5
  54. data/lib/rack/runtime.rb +7 -6
  55. data/lib/rack/sendfile.rb +30 -25
  56. data/lib/rack/show_exceptions.rb +15 -2
  57. data/lib/rack/show_status.rb +17 -7
  58. data/lib/rack/static.rb +8 -8
  59. data/lib/rack/tempfile_reaper.rb +15 -4
  60. data/lib/rack/urlmap.rb +4 -2
  61. data/lib/rack/utils.rb +210 -199
  62. data/lib/rack/version.rb +9 -4
  63. data/lib/rack.rb +5 -76
  64. data/rack.gemspec +6 -6
  65. metadata +19 -31
  66. data/README.rdoc +0 -320
  67. data/bin/rackup +0 -5
  68. data/contrib/rack.png +0 -0
  69. data/contrib/rack.svg +0 -150
  70. data/contrib/rack_logo.svg +0 -164
  71. data/lib/rack/core_ext/regexp.rb +0 -14
  72. data/lib/rack/handler/cgi.rb +0 -59
  73. data/lib/rack/handler/fastcgi.rb +0 -100
  74. data/lib/rack/handler/lsws.rb +0 -61
  75. data/lib/rack/handler/scgi.rb +0 -71
  76. data/lib/rack/handler/thin.rb +0 -36
  77. data/lib/rack/handler/webrick.rb +0 -129
  78. data/lib/rack/handler.rb +0 -104
  79. data/lib/rack/lobster.rb +0 -70
  80. data/lib/rack/server.rb +0 -466
  81. data/lib/rack/session/abstract/id.rb +0 -523
  82. data/lib/rack/session/cookie.rb +0 -204
  83. data/lib/rack/session/memcache.rb +0 -10
  84. data/lib/rack/session/pool.rb +0 -85
data/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # ![Rack](contrib/logo.webp)
2
+
3
+ > **_NOTE:_** Rack v3.0.0beta1 was recently released. Please check the [Upgrade
4
+ > Guide](UPGRADE-GUIDE.md) for more details about migrating your existing
5
+ > servers, middlewares and applications. For detailed information on specific
6
+ > changes, check the [Change Log](CHANGELOG.md).
7
+
8
+ Rack provides a minimal, modular, and adaptable interface for developing web
9
+ applications in Ruby. By wrapping HTTP requests and responses in the simplest
10
+ way possible, it unifies and distills the bridge between web servers, web
11
+ frameworks, and web application into a single method call.
12
+
13
+ The exact details of this are described in the [Rack Specification], which all
14
+ Rack applications should conform to.
15
+
16
+ ## Installation
17
+
18
+ Add the rack gem to your application bundle, or follow the instructions provided
19
+ by a [supported web framework](#supported-web-frameworks):
20
+
21
+ ```bash
22
+ # Install it generally:
23
+ $ gem install rack
24
+
25
+ # or, add it to your current application gemfile:
26
+ $ bundle add rack
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Create a file called `config.ru` with the following contents:
32
+
33
+ ```ruby
34
+ run do |env|
35
+ [200, {}, ["Hello World"]]
36
+ end
37
+ ```
38
+
39
+ Run this using the rackup gem or another [supported web
40
+ server](#supported-web-servers).
41
+
42
+ ```bash
43
+ $ gem install rackup
44
+ $ rackup
45
+ $ curl http://localhost:9292
46
+ Hello World
47
+ ```
48
+
49
+ ## Supported web servers
50
+
51
+ Rack is supported by a wide range of servers, including:
52
+
53
+ * [Agoo](https://github.com/ohler55/agoo)
54
+ * [Falcon](https://github.com/socketry/falcon) **(Rack 3 Compatible)**
55
+ * [Iodine](https://github.com/boazsegev/iodine)
56
+ * [NGINX Unit](https://unit.nginx.org/)
57
+ * [Phusion Passenger](https://www.phusionpassenger.com/) (which is mod_rack for
58
+ Apache and for nginx)
59
+ * [Puma](https://puma.io/)
60
+ * [Thin](https://github.com/macournoyer/thin)
61
+ * [Unicorn](https://yhbt.net/unicorn/)
62
+ * [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/)
63
+ * [Lamby](https://lamby.custominktech.com) (for AWS Lambda)
64
+
65
+ You will need to consult the server documentation to find out what features and
66
+ limitations they may have. In general, any valid Rack app will run the same on
67
+ all these servers, without changing anything.
68
+
69
+ ### Rackup
70
+
71
+ Rack provides a separate gem, [rackup](https://github.com/rack/rackup) which is
72
+ a generic interface for running a Rack application on supported servers, which
73
+ include `WEBRick`, `Puma`, `Falcon` and others.
74
+
75
+ ## Supported web frameworks
76
+
77
+ These frameworks and many others support the [Rack Specification]:
78
+
79
+ * [Camping](https://github.com/camping/camping)
80
+ * [Hanami](https://hanamirb.org/)
81
+ * [Padrino](https://padrinorb.com/)
82
+ * [Roda](https://github.com/jeremyevans/roda) **(Rack 3 Compatible)**
83
+ * [Ruby on Rails](https://rubyonrails.org/)
84
+ * [Sinatra](https://sinatrarb.com/)
85
+ * [Utopia](https://github.com/socketry/utopia) **(Rack 3 Compatible)**
86
+ * [WABuR](https://github.com/ohler55/wabur)
87
+
88
+ ### Older (possibly unsupported) web frameworks
89
+
90
+ * [Ramaze](http://ramaze.net/)
91
+ * [Rum](https://github.com/leahneukirchen/rum)
92
+
93
+ ## Available middleware shipped with Rack
94
+
95
+ Between the server and the framework, Rack can be customized to your
96
+ applications needs using middleware. Rack itself ships with the following
97
+ middleware:
98
+
99
+ * `Rack::CommonLogger` for creating Apache-style logfiles.
100
+ * `Rack::ConditionalGet` for returning [Not
101
+ Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304)
102
+ responses when the response has not changed.
103
+ * `Rack::Config` for modifying the environment before processing the request.
104
+ * `Rack::ContentLength` for setting a `content-length` header based on body
105
+ size.
106
+ * `Rack::ContentType` for setting a default `content-type` header for responses.
107
+ * `Rack::Deflater` for compressing responses with gzip.
108
+ * `Rack::ETag` for setting `etag` header on bodies that can be buffered.
109
+ * `Rack::Events` for providing easy hooks when a request is received and when
110
+ the response is sent.
111
+ * `Rack::Files` for serving static files.
112
+ * `Rack::Head` for returning an empty body for HEAD requests.
113
+ * `Rack::Lint` for checking conformance to the [Rack Specification].
114
+ * `Rack::Lock` for serializing requests using a mutex.
115
+ * `Rack::Logger` for setting a logger to handle logging errors.
116
+ * `Rack::MethodOverride` for modifying the request method based on a submitted
117
+ parameter.
118
+ * `Rack::Recursive` for including data from other paths in the application, and
119
+ for performing internal redirects.
120
+ * `Rack::Reloader` for reloading files if they have been modified.
121
+ * `Rack::Runtime` for including a response header with the time taken to process
122
+ the request.
123
+ * `Rack::Sendfile` for working with web servers that can use optimized file
124
+ serving for file system paths.
125
+ * `Rack::ShowException` for catching unhandled exceptions and presenting them in
126
+ a nice and helpful way with clickable backtrace.
127
+ * `Rack::ShowStatus` for using nice error pages for empty client error
128
+ responses.
129
+ * `Rack::Static` for more configurable serving of static files.
130
+ * `Rack::TempfileReaper` for removing temporary files creating during a request.
131
+
132
+ All these components use the same interface, which is described in detail in the
133
+ [Rack Specification]. These optional components can be used in any way you wish.
134
+
135
+ ### Convenience interfaces
136
+
137
+ If you want to develop outside of existing frameworks, implement your own ones,
138
+ or develop middleware, Rack provides many helpers to create Rack applications
139
+ quickly and without doing the same web stuff all over:
140
+
141
+ * `Rack::Request` which also provides query string parsing and multipart
142
+ handling.
143
+ * `Rack::Response` for convenient generation of HTTP replies and cookie
144
+ handling.
145
+ * `Rack::MockRequest` and `Rack::MockResponse` for efficient and quick testing
146
+ of Rack application without real HTTP round-trips.
147
+ * `Rack::Cascade` for trying additional Rack applications if an application
148
+ returns a not found or method not supported response.
149
+ * `Rack::Directory` for serving files under a given directory, with directory
150
+ indexes.
151
+ * `Rack::MediaType` for parsing content-type headers.
152
+ * `Rack::Mime` for determining content-type based on file extension.
153
+ * `Rack::RewindableInput` for making any IO object rewindable, using a temporary
154
+ file buffer.
155
+ * `Rack::URLMap` to route to multiple applications inside the same process.
156
+
157
+ ## Configuration
158
+
159
+ Rack exposes several configuration parameters to control various features of the
160
+ implementation.
161
+
162
+ ### `param_depth_limit`
163
+
164
+ ```ruby
165
+ Rack::Utils.param_depth_limit = 32 # default
166
+ ```
167
+
168
+ The maximum amount of nesting allowed in parameters. For example, if set to 3,
169
+ this query string would be allowed:
170
+
171
+ ```
172
+ ?a[b][c]=d
173
+ ```
174
+
175
+ but this query string would not be allowed:
176
+
177
+ ```
178
+ ?a[b][c][d]=e
179
+ ```
180
+
181
+ Limiting the depth prevents a possible stack overflow when parsing parameters.
182
+
183
+ ### `multipart_part_limit`
184
+
185
+ ```ruby
186
+ Rack::Utils.multipart_part_limit = 128 # default
187
+ ```
188
+
189
+ The maximum number of parts a request can contain. Accepting too many parts can
190
+ lead to the server running out of file handles.
191
+
192
+ The default is 128, which means that a single request can't upload more than 128
193
+ files at once. Set to 0 for no limit.
194
+
195
+ Can also be set via the `RACK_MULTIPART_PART_LIMIT` environment variable.
196
+
197
+ ## Changelog
198
+
199
+ See [CHANGELOG.md](CHANGELOG.md).
200
+
201
+ ## Contributing
202
+
203
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for specific details about how to make a
204
+ contribution to Rack.
205
+
206
+ Please post bugs, suggestions and patches to [GitHub
207
+ Issues](https://github.com/rack/rack/issues).
208
+
209
+ Please check our [Security Policy](https://github.com/rack/rack/security/policy)
210
+ for responsible disclosure and security bug reporting process. Due to wide usage
211
+ of the library, it is strongly preferred that we manage timing in order to
212
+ provide viable patches at the time of disclosure. Your assistance in this matter
213
+ is greatly appreciated.
214
+
215
+ ## See Also
216
+
217
+ ### `rack-contrib`
218
+
219
+ The plethora of useful middleware created the need for a project that collects
220
+ fresh Rack middleware. `rack-contrib` includes a variety of add-on components
221
+ for Rack and it is easy to contribute new modules.
222
+
223
+ * https://github.com/rack/rack-contrib
224
+
225
+ ### `rack-session`
226
+
227
+ Provides convenient session management for Rack.
228
+
229
+ * https://github.com/rack/rack-session
230
+
231
+ ## Thanks
232
+
233
+ The Rack Core Team, consisting of
234
+
235
+ * Aaron Patterson [tenderlove](https://github.com/tenderlove)
236
+ * Samuel Williams [ioquatix](https://github.com/ioquatix)
237
+ * Jeremy Evans [jeremyevans](https://github.com/jeremyevans)
238
+ * Eileen Uchitelle [eileencodes](https://github.com/eileencodes)
239
+ * Matthew Draper [matthewd](https://github.com/matthewd)
240
+ * Rafael França [rafaelfranca](https://github.com/rafaelfranca)
241
+
242
+ and the Rack Alumni
243
+
244
+ * Ryan Tomayko [rtomayko](https://github.com/rtomayko)
245
+ * Scytrin dai Kinthra [scytrin](https://github.com/scytrin)
246
+ * Leah Neukirchen [leahneukirchen](https://github.com/leahneukirchen)
247
+ * James Tucker [raggi](https://github.com/raggi)
248
+ * Josh Peek [josh](https://github.com/josh)
249
+ * José Valim [josevalim](https://github.com/josevalim)
250
+ * Michael Fellinger [manveru](https://github.com/manveru)
251
+ * Santiago Pastorino [spastorino](https://github.com/spastorino)
252
+ * Konstantin Haase [rkh](https://github.com/rkh)
253
+
254
+ would like to thank:
255
+
256
+ * Adrian Madrid, for the LiteSpeed handler.
257
+ * Christoffer Sawicki, for the first Rails adapter and `Rack::Deflater`.
258
+ * Tim Fletcher, for the HTTP authentication code.
259
+ * Luc Heinrich for the Cookie sessions, the static file handler and bugfixes.
260
+ * Armin Ronacher, for the logo and racktools.
261
+ * Alex Beregszaszi, Alexander Kahn, Anil Wadghule, Aredridel, Ben Alpert, Dan
262
+ Kubb, Daniel Roethlisberger, Matt Todd, Tom Robinson, Phil Hagelberg, S. Brent
263
+ Faulkner, Bosko Milekic, Daniel Rodríguez Troitiño, Genki Takiuchi, Geoffrey
264
+ Grosenbach, Julien Sanchez, Kamal Fariz Mahyuddin, Masayoshi Takahashi,
265
+ Patrick Aljordm, Mig, Kazuhiro Nishiyama, Jon Bardin, Konstantin Haase, Larry
266
+ Siden, Matias Korhonen, Sam Ruby, Simon Chiang, Tim Connor, Timur Batyrshin,
267
+ and Zach Brock for bug fixing and other improvements.
268
+ * Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support and API
269
+ improvements.
270
+ * Yehuda Katz and Carl Lerche for refactoring rackup.
271
+ * Brian Candler, for `Rack::ContentType`.
272
+ * Graham Batty, for improved handler loading.
273
+ * Stephen Bannasch, for bug reports and documentation.
274
+ * Gary Wright, for proposing a better `Rack::Response` interface.
275
+ * Jonathan Buch, for improvements regarding `Rack::Response`.
276
+ * Armin Röhrl, for tracking down bugs in the Cookie generator.
277
+ * Alexander Kellett for testing the Gem and reviewing the announcement.
278
+ * Marcus Rückert, for help with configuring and debugging lighttpd.
279
+ * The WSGI team for the well-done and documented work they've done and Rack
280
+ builds up on.
281
+ * All bug reporters and patch contributors not mentioned above.
282
+
283
+ ## License
284
+
285
+ Rack is released under the [MIT License](MIT-LICENSE).
286
+
287
+ [Rack Specification]: SPEC.rdoc
data/Rakefile CHANGED
@@ -98,8 +98,24 @@ task "test_cov" do
98
98
  Rake::Task['test:regular'].invoke
99
99
  end
100
100
 
101
+ desc "Run separate tests for each test file, to test directly requiring components"
102
+ task "test:separate" do
103
+ fails = []
104
+ FileList["test/**/spec_*.rb"].each do |file|
105
+ puts "#{FileUtils::RUBY} -w #{file}"
106
+ fails << file unless system({'SEPARATE'=>'1'}, FileUtils::RUBY, '-w', file)
107
+ end
108
+ if fails.empty?
109
+ puts 'All test files passed'
110
+ else
111
+ puts "Failures in the following test files:"
112
+ puts fails
113
+ raise "At least one separate test failed"
114
+ end
115
+ end
116
+
101
117
  desc "Run all the fast + platform agnostic tests"
102
- task test: %w[spec test:regular]
118
+ task test: %w[spec test:regular test:separate]
103
119
 
104
120
  desc "Run all the tests we run on CI"
105
121
  task ci: :test
@@ -119,12 +135,29 @@ task rdoc: %w[changelog spec] do
119
135
  cp "contrib/rdoc.css", "doc/rdoc.css"
120
136
  end
121
137
 
122
- task pushdoc: :rdoc do
123
- sh "rsync -avz doc/ rack.rubyforge.org:/var/www/gforge-projects/rack/doc/"
138
+ def clone_and_test(url, name, command)
139
+ path = "external/#{name}"
140
+ FileUtils.rm_rf path
141
+ FileUtils.mkdir_p path
142
+
143
+ sh("git clone #{url} #{path}")
144
+
145
+ # I tried using `bundle config --local local.async ../` but it simply doesn't work.
146
+ File.open("#{path}/Gemfile", "a") do |file|
147
+ file.puts("gem 'rack', path: '../../'")
148
+ file.puts("gem 'rack-session', github: 'rack/rack-session'") if name == 'rack-attack'
149
+ end
150
+
151
+ sh("cd #{path} && bundle install && #{command}")
124
152
  end
125
153
 
126
- task pushsite: :pushdoc do
127
- sh "cd site && git gc"
128
- sh "rsync -avz site/ rack.rubyforge.org:/var/www/gforge-projects/rack/"
129
- sh "cd site && git push"
154
+ task :external do
155
+ # In order not to interfere with external tests: rename our config file
156
+ FileUtils.mv ".rubocop.yml", ".rack.rubocop.yml.disabled"
157
+
158
+ Bundler.with_clean_env do
159
+ clone_and_test("https://github.com/rack/rack-attack", "rack-attack", "bundle exec rake test")
160
+ clone_and_test("https://github.com/rack/rack-cache", "rack-cache", "bundle exec rake")
161
+ clone_and_test("https://github.com/socketry/falcon", "falcon", "bundle exec rspec")
162
+ end
130
163
  end