rack 1.0.1 → 2.2.21

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 (147) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +829 -0
  3. data/CONTRIBUTING.md +136 -0
  4. data/{COPYING → MIT-LICENSE} +4 -2
  5. data/README.rdoc +355 -0
  6. data/Rakefile +64 -98
  7. data/SPEC.rdoc +292 -0
  8. data/bin/rackup +3 -174
  9. data/contrib/rack.png +0 -0
  10. data/contrib/rack.svg +150 -0
  11. data/contrib/rack_logo.svg +164 -111
  12. data/contrib/rdoc.css +412 -0
  13. data/example/lobster.ru +2 -0
  14. data/example/protectedlobster.rb +4 -2
  15. data/example/protectedlobster.ru +3 -1
  16. data/lib/rack/auth/abstract/handler.rb +7 -5
  17. data/lib/rack/auth/abstract/request.rb +12 -2
  18. data/lib/rack/auth/basic.rb +6 -4
  19. data/lib/rack/auth/digest/md5.rb +20 -13
  20. data/lib/rack/auth/digest/nonce.rb +6 -4
  21. data/lib/rack/auth/digest/params.rb +11 -12
  22. data/lib/rack/auth/digest/request.rb +15 -12
  23. data/lib/rack/body_proxy.rb +45 -0
  24. data/lib/rack/builder.rb +213 -19
  25. data/lib/rack/cascade.rb +50 -18
  26. data/lib/rack/chunked.rb +95 -27
  27. data/lib/rack/common_logger.rb +84 -0
  28. data/lib/rack/conditional_get.rb +83 -0
  29. data/lib/rack/config.rb +22 -0
  30. data/lib/rack/content_length.rb +19 -10
  31. data/lib/rack/content_type.rb +12 -5
  32. data/lib/rack/core_ext/regexp.rb +14 -0
  33. data/lib/rack/deflater.rb +90 -42
  34. data/lib/rack/directory.rb +118 -72
  35. data/lib/rack/etag.rb +77 -0
  36. data/lib/rack/events.rb +153 -0
  37. data/lib/rack/file.rb +4 -85
  38. data/lib/rack/files.rb +218 -0
  39. data/lib/rack/handler/cgi.rb +22 -24
  40. data/lib/rack/handler/fastcgi.rb +34 -24
  41. data/lib/rack/handler/lsws.rb +16 -15
  42. data/lib/rack/handler/scgi.rb +38 -29
  43. data/lib/rack/handler/thin.rb +23 -7
  44. data/lib/rack/handler/webrick.rb +95 -37
  45. data/lib/rack/handler.rb +49 -14
  46. data/lib/rack/head.rb +19 -13
  47. data/lib/rack/lint.rb +466 -217
  48. data/lib/rack/lobster.rb +19 -14
  49. data/lib/rack/lock.rb +24 -8
  50. data/lib/rack/logger.rb +20 -0
  51. data/lib/rack/media_type.rb +53 -0
  52. data/lib/rack/method_override.rb +52 -0
  53. data/lib/rack/mime.rb +652 -171
  54. data/lib/rack/mock.rb +203 -64
  55. data/lib/rack/multipart/generator.rb +97 -0
  56. data/lib/rack/multipart/parser.rb +440 -0
  57. data/lib/rack/multipart/uploaded_file.rb +41 -0
  58. data/lib/rack/multipart.rb +64 -0
  59. data/lib/rack/null_logger.rb +39 -0
  60. data/lib/rack/query_parser.rb +266 -0
  61. data/lib/rack/recursive.rb +18 -11
  62. data/lib/rack/reloader.rb +13 -5
  63. data/lib/rack/request.rb +607 -191
  64. data/lib/rack/response.rb +245 -110
  65. data/lib/rack/rewindable_input.rb +15 -21
  66. data/lib/rack/runtime.rb +34 -0
  67. data/lib/rack/sendfile.rb +192 -0
  68. data/lib/rack/server.rb +466 -0
  69. data/lib/rack/session/abstract/id.rb +449 -68
  70. data/lib/rack/session/cookie.rb +159 -47
  71. data/lib/rack/session/memcache.rb +4 -103
  72. data/lib/rack/session/pool.rb +39 -49
  73. data/lib/rack/show_exceptions.rb +390 -0
  74. data/lib/rack/{showstatus.rb → show_status.rb} +21 -14
  75. data/lib/rack/static.rb +164 -14
  76. data/lib/rack/tempfile_reaper.rb +22 -0
  77. data/lib/rack/urlmap.rb +60 -18
  78. data/lib/rack/utils.rb +508 -277
  79. data/lib/rack/version.rb +29 -0
  80. data/lib/rack.rb +85 -34
  81. data/rack.gemspec +43 -51
  82. metadata +119 -207
  83. data/KNOWN-ISSUES +0 -18
  84. data/RDOX +0 -428
  85. data/README +0 -364
  86. data/SPEC +0 -164
  87. data/lib/rack/adapter/camping.rb +0 -22
  88. data/lib/rack/auth/openid.rb +0 -480
  89. data/lib/rack/commonlogger.rb +0 -61
  90. data/lib/rack/conditionalget.rb +0 -47
  91. data/lib/rack/handler/evented_mongrel.rb +0 -8
  92. data/lib/rack/handler/mongrel.rb +0 -87
  93. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  94. data/lib/rack/methodoverride.rb +0 -27
  95. data/lib/rack/showexceptions.rb +0 -349
  96. data/test/cgi/lighttpd.conf +0 -20
  97. data/test/cgi/test +0 -9
  98. data/test/cgi/test.fcgi +0 -8
  99. data/test/cgi/test.ru +0 -7
  100. data/test/multipart/binary +0 -0
  101. data/test/multipart/empty +0 -10
  102. data/test/multipart/ie +0 -6
  103. data/test/multipart/nested +0 -10
  104. data/test/multipart/none +0 -9
  105. data/test/multipart/semicolon +0 -6
  106. data/test/multipart/text +0 -10
  107. data/test/spec_rack_auth_basic.rb +0 -73
  108. data/test/spec_rack_auth_digest.rb +0 -226
  109. data/test/spec_rack_auth_openid.rb +0 -84
  110. data/test/spec_rack_builder.rb +0 -84
  111. data/test/spec_rack_camping.rb +0 -51
  112. data/test/spec_rack_cascade.rb +0 -50
  113. data/test/spec_rack_cgi.rb +0 -89
  114. data/test/spec_rack_chunked.rb +0 -62
  115. data/test/spec_rack_commonlogger.rb +0 -32
  116. data/test/spec_rack_conditionalget.rb +0 -41
  117. data/test/spec_rack_content_length.rb +0 -43
  118. data/test/spec_rack_content_type.rb +0 -30
  119. data/test/spec_rack_deflater.rb +0 -127
  120. data/test/spec_rack_directory.rb +0 -61
  121. data/test/spec_rack_fastcgi.rb +0 -89
  122. data/test/spec_rack_file.rb +0 -75
  123. data/test/spec_rack_handler.rb +0 -43
  124. data/test/spec_rack_head.rb +0 -30
  125. data/test/spec_rack_lint.rb +0 -521
  126. data/test/spec_rack_lobster.rb +0 -45
  127. data/test/spec_rack_lock.rb +0 -38
  128. data/test/spec_rack_methodoverride.rb +0 -60
  129. data/test/spec_rack_mock.rb +0 -157
  130. data/test/spec_rack_mongrel.rb +0 -189
  131. data/test/spec_rack_recursive.rb +0 -77
  132. data/test/spec_rack_request.rb +0 -504
  133. data/test/spec_rack_response.rb +0 -218
  134. data/test/spec_rack_rewindable_input.rb +0 -118
  135. data/test/spec_rack_session_cookie.rb +0 -82
  136. data/test/spec_rack_session_memcache.rb +0 -240
  137. data/test/spec_rack_session_pool.rb +0 -172
  138. data/test/spec_rack_showexceptions.rb +0 -21
  139. data/test/spec_rack_showstatus.rb +0 -72
  140. data/test/spec_rack_static.rb +0 -37
  141. data/test/spec_rack_thin.rb +0 -91
  142. data/test/spec_rack_urlmap.rb +0 -185
  143. data/test/spec_rack_utils.rb +0 -387
  144. data/test/spec_rack_webrick.rb +0 -130
  145. data/test/testrequest.rb +0 -57
  146. data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
  147. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
data/Rakefile CHANGED
@@ -1,17 +1,27 @@
1
- # Rakefile for Rack. -*-ruby-*-
2
- require 'rake/rdoctask'
3
- require 'rake/testtask'
1
+ # frozen_string_literal: true
4
2
 
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
5
 
6
6
  desc "Run all the tests"
7
- task :default => [:test]
7
+ task default: :test
8
8
 
9
+ desc "Install gem dependencies"
10
+ task :deps do
11
+ require 'rubygems'
12
+ spec = Gem::Specification.load('rack.gemspec')
13
+ spec.dependencies.each do |dep|
14
+ reqs = dep.requirements_list
15
+ reqs = (["-v"] * reqs.size).zip(reqs).flatten
16
+ # Use system over sh, because we want to ignore errors!
17
+ system Gem.ruby, "-S", "gem", "install", '--conservative', dep.name, *reqs
18
+ end
19
+ end
9
20
 
10
21
  desc "Make an archive as .tar.gz"
11
- task :dist => [:chmod, :changelog, :rdoc, "SPEC", "rack.gemspec"] do
12
- FileUtils.touch("RDOX")
22
+ task dist: %w[chmod changelog spec rdoc] do
13
23
  sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
14
- sh "pax -waf #{release}.tar -s ':^:#{release}/:' RDOX SPEC ChangeLog doc rack.gemspec"
24
+ sh "pax -waf #{release}.tar -s ':^:#{release}/:' SPEC.rdoc ChangeLog doc rack.gemspec"
15
25
  sh "gzip -f -9 #{release}.tar"
16
26
  end
17
27
 
@@ -24,35 +34,29 @@ task :officialrelease do
24
34
  sh "mv stage/#{release}.tar.gz stage/#{release}.gem ."
25
35
  end
26
36
 
27
- task :officialrelease_really => [:fulltest, "RDOX", "SPEC", :dist, :gem] do
28
- sh "sha1sum #{release}.tar.gz #{release}.gem"
29
- end
30
-
31
-
32
- def version
33
- abort "You need to pass VERSION=... to build packages." unless ENV["VERSION"]
34
- ENV["VERSION"]
37
+ task officialrelease_really: %w[spec dist gem] do
38
+ sh "shasum #{release}.tar.gz #{release}.gem"
35
39
  end
36
40
 
37
41
  def release
38
- "rack-#{version}"
42
+ "rack-" + File.read('lib/rack/version.rb')[/RELEASE += +([\"\'])([\d][\w\.]+)\1/, 2]
39
43
  end
40
44
 
41
- def manifest
42
- `git ls-files`.split("\n")
43
- end
44
-
45
-
46
45
  desc "Make binaries executable"
47
46
  task :chmod do
48
- Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
49
- Dir["test/cgi/test*"].each { |binary| File.chmod(0775, binary) }
47
+ Dir["bin/*"].each { |binary| File.chmod(0755, binary) }
48
+ Dir["test/cgi/test*"].each { |binary| File.chmod(0755, binary) }
50
49
  end
51
50
 
52
51
  desc "Generate a ChangeLog"
53
- task :changelog do
52
+ task changelog: "ChangeLog"
53
+
54
+ file '.git/index'
55
+ file "ChangeLog" => '.git/index' do
54
56
  File.open("ChangeLog", "w") { |out|
55
- `git log -z`.split("\0").map { |chunk|
57
+ log = `git log -z`
58
+ log.force_encoding(Encoding::BINARY)
59
+ log.split("\0").map { |chunk|
56
60
  author = chunk[/Author: (.*)/, 1].strip
57
61
  date = chunk[/Date: (.*)/, 1].strip
58
62
  desc, detail = $'.strip.split("\n", 2)
@@ -67,98 +71,60 @@ task :changelog do
67
71
  }
68
72
  end
69
73
 
70
-
71
- desc "Generate RDox"
72
- task "RDOX" do
73
- sh "specrb -Ilib:test -a --rdox >RDOX"
74
- end
75
-
76
74
  desc "Generate Rack Specification"
77
- task "SPEC" do
78
- File.open("SPEC", "wb") { |file|
75
+ task spec: "SPEC.rdoc"
76
+
77
+ file 'lib/rack/lint.rb'
78
+ file "SPEC.rdoc" => 'lib/rack/lint.rb' do
79
+ File.open("SPEC.rdoc", "wb") { |file|
79
80
  IO.foreach("lib/rack/lint.rb") { |line|
80
- if line =~ /## (.*)/
81
+ if line =~ /^\s*## ?(.*)/
81
82
  file.puts $1
82
83
  end
83
84
  }
84
85
  }
85
86
  end
86
87
 
87
- desc "Run all the fast tests"
88
- task :test do
89
- sh "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS'] || '-t "^(?!Rack::Handler|Rack::Adapter|Rack::Session::Memcache|Rack::Auth::OpenID)"'}"
88
+ Rake::TestTask.new("test:regular") do |t|
89
+ t.libs << "test"
90
+ t.test_files = FileList["test/**/*_test.rb", "test/**/spec_*.rb", "test/gemloader.rb"]
91
+ t.warning = false
92
+ t.verbose = true
90
93
  end
91
94
 
92
- desc "Run all the tests"
93
- task :fulltest => [:chmod] do
94
- sh "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
95
+ desc "Run tests with coverage"
96
+ task "test_cov" do
97
+ ENV['COVERAGE'] = '1'
98
+ Rake::Task['test:regular'].invoke
95
99
  end
96
100
 
97
- begin
98
- require 'rubygems'
99
- rescue LoadError
100
- # Too bad.
101
- else
102
- task "rack.gemspec" do
103
- spec = Gem::Specification.new do |s|
104
- s.name = "rack"
105
- s.version = version
106
- s.platform = Gem::Platform::RUBY
107
- s.summary = "a modular Ruby webserver interface"
108
-
109
- s.description = <<-EOF
110
- Rack provides minimal, modular and adaptable interface for developing
111
- web applications in Ruby. By wrapping HTTP requests and responses in
112
- the simplest way possible, it unifies and distills the API for web
113
- servers, web frameworks, and software in between (the so-called
114
- middleware) into a single method call.
115
-
116
- Also see http://rack.rubyforge.org.
117
- EOF
118
-
119
- s.files = manifest + %w(SPEC RDOX rack.gemspec)
120
- s.bindir = 'bin'
121
- s.executables << 'rackup'
122
- s.require_path = 'lib'
123
- s.has_rdoc = true
124
- s.extra_rdoc_files = ['README', 'SPEC', 'RDOX', 'KNOWN-ISSUES']
125
- s.test_files = Dir['test/{test,spec}_*.rb']
126
-
127
- s.author = 'Christian Neukirchen'
128
- s.email = 'chneukirchen@gmail.com'
129
- s.homepage = 'http://rack.rubyforge.org'
130
- s.rubyforge_project = 'rack'
131
-
132
- s.add_development_dependency 'test-spec'
133
-
134
- s.add_development_dependency 'camping'
135
- s.add_development_dependency 'fcgi'
136
- s.add_development_dependency 'memcache-client'
137
- s.add_development_dependency 'mongrel'
138
- s.add_development_dependency 'ruby-openid', '~> 2.0.0'
139
- s.add_development_dependency 'thin'
140
- end
141
-
142
- File.open("rack.gemspec", "w") { |f| f << spec.to_ruby }
143
- end
101
+ desc "Run all the fast + platform agnostic tests"
102
+ task test: %w[spec test:regular]
144
103
 
145
- task :gem => ["rack.gemspec", "SPEC"] do
146
- FileUtils.touch("RDOX")
147
- sh "gem build rack.gemspec"
148
- end
104
+ desc "Run all the tests we run on CI"
105
+ task ci: :test
106
+
107
+ task gem: :spec do
108
+ sh "gem build rack.gemspec"
149
109
  end
150
110
 
111
+ task doc: :rdoc
112
+
151
113
  desc "Generate RDoc documentation"
152
- task :rdoc do
153
- sh(*%w{rdoc --line-numbers --main README
114
+ task rdoc: %w[changelog spec] do
115
+ sh(*%w{rdoc --line-numbers --main README.rdoc
154
116
  --title 'Rack\ Documentation' --charset utf-8 -U -o doc} +
155
- %w{README KNOWN-ISSUES SPEC RDOX} +
156
- Dir["lib/**/*.rb"])
117
+ %w{README.rdoc KNOWN-ISSUES SPEC.rdoc ChangeLog} +
118
+ `git ls-files lib/\*\*/\*.rb`.strip.split)
119
+ cp "contrib/rdoc.css", "doc/rdoc.css"
120
+ end
121
+
122
+ task pushdoc: :rdoc do
123
+ sh "rsync -avz doc/ rack.rubyforge.org:/var/www/gforge-projects/rack/doc/"
157
124
  end
158
125
 
159
- task :pushsite => [:rdoc] do
126
+ task pushsite: :pushdoc do
160
127
  sh "cd site && git gc"
161
- sh "rsync -avz doc/ chneukirchen@rack.rubyforge.org:/var/www/gforge-projects/rack/doc/"
162
- sh "rsync -avz site/ chneukirchen@rack.rubyforge.org:/var/www/gforge-projects/rack/"
128
+ sh "rsync -avz site/ rack.rubyforge.org:/var/www/gforge-projects/rack/"
163
129
  sh "cd site && git push"
164
130
  end
data/SPEC.rdoc ADDED
@@ -0,0 +1,292 @@
1
+ This specification aims to formalize the Rack protocol. You
2
+ can (and should) use Rack::Lint to enforce it.
3
+
4
+ When you develop middleware, be sure to add a Lint before and
5
+ after to catch all mistakes.
6
+ = Rack applications
7
+ A Rack application is a Ruby object (not a class) that
8
+ responds to +call+.
9
+ It takes exactly one argument, the *environment*
10
+ and returns an Array of exactly three values:
11
+ The *status*,
12
+ the *headers*,
13
+ and the *body*.
14
+ == The Environment
15
+ The environment must be an unfrozen instance of Hash that includes
16
+ CGI-like headers. The application is free to modify the
17
+ environment.
18
+
19
+ The environment is required to include these variables
20
+ (adopted from PEP333), except when they'd be empty, but see
21
+ below.
22
+ <tt>REQUEST_METHOD</tt>:: The HTTP request method, such as
23
+ "GET" or "POST". This cannot ever
24
+ be an empty string, and so is
25
+ always required.
26
+ <tt>SCRIPT_NAME</tt>:: The initial portion of the request
27
+ URL's "path" that corresponds to the
28
+ application object, so that the
29
+ application knows its virtual
30
+ "location". This may be an empty
31
+ string, if the application corresponds
32
+ to the "root" of the server.
33
+ <tt>PATH_INFO</tt>:: The remainder of the request URL's
34
+ "path", designating the virtual
35
+ "location" of the request's target
36
+ within the application. This may be an
37
+ empty string, if the request URL targets
38
+ the application root and does not have a
39
+ trailing slash. This value may be
40
+ percent-encoded when originating from
41
+ a URL.
42
+ <tt>QUERY_STRING</tt>:: The portion of the request URL that
43
+ follows the <tt>?</tt>, if any. May be
44
+ empty, but is always required!
45
+ <tt>SERVER_NAME</tt>:: When combined with <tt>SCRIPT_NAME</tt> and
46
+ <tt>PATH_INFO</tt>, these variables can be
47
+ used to complete the URL. Note, however,
48
+ that <tt>HTTP_HOST</tt>, if present,
49
+ should be used in preference to
50
+ <tt>SERVER_NAME</tt> for reconstructing
51
+ the request URL.
52
+ <tt>SERVER_NAME</tt> can never be an empty
53
+ string, and so is always required.
54
+ <tt>SERVER_PORT</tt>:: An optional +Integer+ which is the port the
55
+ server is running on. Should be specified if
56
+ the server is running on a non-standard port.
57
+ <tt>HTTP_</tt> Variables:: Variables corresponding to the
58
+ client-supplied HTTP request
59
+ headers (i.e., variables whose
60
+ names begin with <tt>HTTP_</tt>). The
61
+ presence or absence of these
62
+ variables should correspond with
63
+ the presence or absence of the
64
+ appropriate HTTP header in the
65
+ request. See
66
+ {RFC3875 section 4.1.18}[https://tools.ietf.org/html/rfc3875#section-4.1.18]
67
+ for specific behavior.
68
+ In addition to this, the Rack environment must include these
69
+ Rack-specific variables:
70
+ <tt>rack.version</tt>:: The Array representing this version of Rack
71
+ See Rack::VERSION, that corresponds to
72
+ the version of this SPEC.
73
+ <tt>rack.url_scheme</tt>:: +http+ or +https+, depending on the
74
+ request URL.
75
+ <tt>rack.input</tt>:: See below, the input stream.
76
+ <tt>rack.errors</tt>:: See below, the error stream.
77
+ <tt>rack.multithread</tt>:: true if the application object may be
78
+ simultaneously invoked by another thread
79
+ in the same process, false otherwise.
80
+ <tt>rack.multiprocess</tt>:: true if an equivalent application object
81
+ may be simultaneously invoked by another
82
+ process, false otherwise.
83
+ <tt>rack.run_once</tt>:: true if the server expects
84
+ (but does not guarantee!) that the
85
+ application will only be invoked this one
86
+ time during the life of its containing
87
+ process. Normally, this will only be true
88
+ for a server based on CGI
89
+ (or something similar).
90
+ <tt>rack.hijack?</tt>:: present and true if the server supports
91
+ connection hijacking. See below, hijacking.
92
+ <tt>rack.hijack</tt>:: an object responding to #call that must be
93
+ called at least once before using
94
+ rack.hijack_io.
95
+ It is recommended #call return rack.hijack_io
96
+ as well as setting it in env if necessary.
97
+ <tt>rack.hijack_io</tt>:: if rack.hijack? is true, and rack.hijack
98
+ has received #call, this will contain
99
+ an object resembling an IO. See hijacking.
100
+ Additional environment specifications have approved to
101
+ standardized middleware APIs. None of these are required to
102
+ be implemented by the server.
103
+ <tt>rack.session</tt>:: A hash like interface for storing
104
+ request session data.
105
+ The store must implement:
106
+ store(key, value) (aliased as []=);
107
+ fetch(key, default = nil) (aliased as []);
108
+ delete(key);
109
+ clear;
110
+ to_hash (returning unfrozen Hash instance);
111
+ <tt>rack.logger</tt>:: A common object interface for logging messages.
112
+ The object must implement:
113
+ info(message, &block)
114
+ debug(message, &block)
115
+ warn(message, &block)
116
+ error(message, &block)
117
+ fatal(message, &block)
118
+ <tt>rack.multipart.buffer_size</tt>:: An Integer hint to the multipart parser as to what chunk size to use for reads and writes.
119
+ <tt>rack.multipart.tempfile_factory</tt>:: An object responding to #call with two arguments, the filename and content_type given for the multipart form field, and returning an IO-like object that responds to #<< and optionally #rewind. This factory will be used to instantiate the tempfile for each multipart form file upload field, rather than the default class of Tempfile.
120
+ The server or the application can store their own data in the
121
+ environment, too. The keys must contain at least one dot,
122
+ and should be prefixed uniquely. The prefix <tt>rack.</tt>
123
+ is reserved for use with the Rack core distribution and other
124
+ accepted specifications and must not be used otherwise.
125
+
126
+ The <tt>SERVER_PORT</tt> must be an Integer if set.
127
+ The <tt>SERVER_NAME</tt> must be a valid authority as defined by RFC7540.
128
+ The <tt>HTTP_HOST</tt> must be a valid authority as defined by RFC7540.
129
+ The environment must not contain the keys
130
+ <tt>HTTP_CONTENT_TYPE</tt> or <tt>HTTP_CONTENT_LENGTH</tt>
131
+ (use the versions without <tt>HTTP_</tt>).
132
+ The CGI keys (named without a period) must have String values.
133
+ If the string values for CGI keys contain non-ASCII characters,
134
+ they should use ASCII-8BIT encoding.
135
+ There are the following restrictions:
136
+ * <tt>rack.version</tt> must be an array of Integers.
137
+ * <tt>rack.url_scheme</tt> must either be +http+ or +https+.
138
+ * There must be a valid input stream in <tt>rack.input</tt>.
139
+ * There must be a valid error stream in <tt>rack.errors</tt>.
140
+ * There may be a valid hijack stream in <tt>rack.hijack_io</tt>
141
+ * The <tt>REQUEST_METHOD</tt> must be a valid token.
142
+ * The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>
143
+ * The <tt>PATH_INFO</tt>, if non-empty, must start with <tt>/</tt>
144
+ * The <tt>CONTENT_LENGTH</tt>, if given, must consist of digits only.
145
+ * One of <tt>SCRIPT_NAME</tt> or <tt>PATH_INFO</tt> must be
146
+ set. <tt>PATH_INFO</tt> should be <tt>/</tt> if
147
+ <tt>SCRIPT_NAME</tt> is empty.
148
+ <tt>SCRIPT_NAME</tt> never should be <tt>/</tt>, but instead be empty.
149
+ === The Input Stream
150
+
151
+ The input stream is an IO-like object which contains the raw HTTP
152
+ POST data.
153
+ When applicable, its external encoding must be "ASCII-8BIT" and it
154
+ must be opened in binary mode, for Ruby 1.9 compatibility.
155
+ The input stream must respond to +gets+, +each+, +read+ and +rewind+.
156
+ * +gets+ must be called without arguments and return a string,
157
+ or +nil+ on EOF.
158
+ * +read+ behaves like IO#read.
159
+ Its signature is <tt>read([length, [buffer]])</tt>.
160
+
161
+ If given, +length+ must be a non-negative Integer (>= 0) or +nil+,
162
+ and +buffer+ must be a String and may not be nil.
163
+
164
+ If +length+ is given and not nil, then this method reads at most
165
+ +length+ bytes from the input stream.
166
+
167
+ If +length+ is not given or nil, then this method reads
168
+ all data until EOF.
169
+
170
+ When EOF is reached, this method returns nil if +length+ is given
171
+ and not nil, or "" if +length+ is not given or is nil.
172
+
173
+ If +buffer+ is given, then the read data will be placed
174
+ into +buffer+ instead of a newly created String object.
175
+ * +each+ must be called without arguments and only yield Strings.
176
+ * +rewind+ must be called without arguments. It rewinds the input
177
+ stream back to the beginning. It must not raise Errno::ESPIPE:
178
+ that is, it may not be a pipe or a socket. Therefore, handler
179
+ developers must buffer the input data into some rewindable object
180
+ if the underlying input stream is not rewindable.
181
+ * +close+ must never be called on the input stream.
182
+ === The Error Stream
183
+ The error stream must respond to +puts+, +write+ and +flush+.
184
+ * +puts+ must be called with a single argument that responds to +to_s+.
185
+ * +write+ must be called with a single argument that is a String.
186
+ * +flush+ must be called without arguments and must be called
187
+ in order to make the error appear for sure.
188
+ * +close+ must never be called on the error stream.
189
+ === Hijacking
190
+ ==== Request (before status)
191
+ If rack.hijack? is true then rack.hijack must respond to #call.
192
+ rack.hijack must return the io that will also be assigned (or is
193
+ already present, in rack.hijack_io.
194
+
195
+ rack.hijack_io must respond to:
196
+ <tt>read, write, read_nonblock, write_nonblock, flush, close,
197
+ close_read, close_write, closed?</tt>
198
+
199
+ The semantics of these IO methods must be a best effort match to
200
+ those of a normal ruby IO or Socket object, using standard
201
+ arguments and raising standard exceptions. Servers are encouraged
202
+ to simply pass on real IO objects, although it is recognized that
203
+ this approach is not directly compatible with SPDY and HTTP 2.0.
204
+
205
+ IO provided in rack.hijack_io should preference the
206
+ IO::WaitReadable and IO::WaitWritable APIs wherever supported.
207
+
208
+ There is a deliberate lack of full specification around
209
+ rack.hijack_io, as semantics will change from server to server.
210
+ Users are encouraged to utilize this API with a knowledge of their
211
+ server choice, and servers may extend the functionality of
212
+ hijack_io to provide additional features to users. The purpose of
213
+ rack.hijack is for Rack to "get out of the way", as such, Rack only
214
+ provides the minimum of specification and support.
215
+
216
+ If rack.hijack? is false, then rack.hijack should not be set.
217
+
218
+ If rack.hijack? is false, then rack.hijack_io should not be set.
219
+ ==== Response (after headers)
220
+ It is also possible to hijack a response after the status and headers
221
+ have been sent.
222
+ In order to do this, an application may set the special header
223
+ <tt>rack.hijack</tt> to an object that responds to <tt>call</tt>
224
+ accepting an argument that conforms to the <tt>rack.hijack_io</tt>
225
+ protocol.
226
+
227
+ After the headers have been sent, and this hijack callback has been
228
+ called, the application is now responsible for the remaining lifecycle
229
+ of the IO. The application is also responsible for maintaining HTTP
230
+ semantics. Of specific note, in almost all cases in the current SPEC,
231
+ applications will have wanted to specify the header Connection:close in
232
+ HTTP/1.1, and not Connection:keep-alive, as there is no protocol for
233
+ returning hijacked sockets to the web server. For that purpose, use the
234
+ body streaming API instead (progressively yielding strings via each).
235
+
236
+ Servers must ignore the <tt>body</tt> part of the response tuple when
237
+ the <tt>rack.hijack</tt> response API is in use.
238
+
239
+ The special response header <tt>rack.hijack</tt> must only be set
240
+ if the request env has <tt>rack.hijack?</tt> <tt>true</tt>.
241
+ ==== Conventions
242
+ * Middleware should not use hijack unless it is handling the whole
243
+ response.
244
+ * Middleware may wrap the IO object for the response pattern.
245
+ * Middleware should not wrap the IO object for the request pattern. The
246
+ request pattern is intended to provide the hijacker with "raw tcp".
247
+ == The Response
248
+ === The Status
249
+ This is an HTTP status. When parsed as integer (+to_i+), it must be
250
+ greater than or equal to 100.
251
+ === The Headers
252
+ The header must respond to +each+, and yield values of key and value.
253
+ The header keys must be Strings.
254
+ Special headers starting "rack." are for communicating with the
255
+ server, and must not be sent back to the client.
256
+ The header must not contain a +Status+ key.
257
+ The header must conform to RFC7230 token specification, i.e. cannot
258
+ contain non-printable ASCII, DQUOTE or "(),/:;<=>?@[\]{}".
259
+ The values of the header must be Strings,
260
+ consisting of lines (for multiple header values, e.g. multiple
261
+ <tt>Set-Cookie</tt> values) separated by "\\n".
262
+ The lines must not contain characters below 037.
263
+ === The Content-Type
264
+ There must not be a <tt>Content-Type</tt>, when the +Status+ is 1xx,
265
+ 204 or 304.
266
+ === The Content-Length
267
+ There must not be a <tt>Content-Length</tt> header when the
268
+ +Status+ is 1xx, 204 or 304.
269
+ === The Body
270
+ The Body must respond to +each+
271
+ and must only yield String values.
272
+
273
+ The Body itself should not be an instance of String, as this will
274
+ break in Ruby 1.9.
275
+
276
+ If the Body responds to +close+, it will be called after iteration. If
277
+ the body is replaced by a middleware after action, the original body
278
+ must be closed first, if it responds to close.
279
+
280
+ If the Body responds to +to_path+, it must return a String
281
+ identifying the location of a file whose contents are identical
282
+ to that produced by calling +each+; this may be used by the
283
+ server as an alternative, possibly more efficient way to
284
+ transport the response.
285
+
286
+ The Body commonly is an Array of Strings, the application
287
+ instance itself, or a File-like object.
288
+ == Thanks
289
+ Some parts of this specification are adopted from PEP333: Python
290
+ Web Server Gateway Interface
291
+ v1.0 (http://www.python.org/dev/peps/pep-0333/). I'd like to thank
292
+ everyone involved in that effort.
data/bin/rackup CHANGED
@@ -1,176 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- ruby -*-
2
+ # frozen_string_literal: true
3
3
 
4
- $LOAD_PATH.unshift File.expand_path("#{__FILE__}/../../lib")
5
- autoload :Rack, 'rack'
6
-
7
- require 'optparse'
8
-
9
- automatic = false
10
- server = nil
11
- env = "development"
12
- daemonize = false
13
- pid = nil
14
- options = {:Port => 9292, :Host => "0.0.0.0", :AccessLog => []}
15
-
16
- # Don't evaluate CGI ISINDEX parameters.
17
- # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html
18
- ARGV.clear if ENV.include?("REQUEST_METHOD")
19
-
20
- opts = OptionParser.new("", 24, ' ') { |opts|
21
- opts.banner = "Usage: rackup [ruby options] [rack options] [rackup config]"
22
-
23
- opts.separator ""
24
- opts.separator "Ruby options:"
25
-
26
- lineno = 1
27
- opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
28
- eval line, TOPLEVEL_BINDING, "-e", lineno
29
- lineno += 1
30
- }
31
-
32
- opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
33
- $DEBUG = true
34
- }
35
- opts.on("-w", "--warn", "turn warnings on for your script") {
36
- $-w = true
37
- }
38
-
39
- opts.on("-I", "--include PATH",
40
- "specify $LOAD_PATH (may be used more than once)") { |path|
41
- $LOAD_PATH.unshift(*path.split(":"))
42
- }
43
-
44
- opts.on("-r", "--require LIBRARY",
45
- "require the library, before executing your script") { |library|
46
- require library
47
- }
48
-
49
- opts.separator ""
50
- opts.separator "Rack options:"
51
- opts.on("-s", "--server SERVER", "serve using SERVER (webrick/mongrel)") { |s|
52
- server = s
53
- }
54
-
55
- opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") { |host|
56
- options[:Host] = host
57
- }
58
-
59
- opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port|
60
- options[:Port] = port
61
- }
62
-
63
- opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
64
- env = e
65
- }
66
-
67
- opts.on("-D", "--daemonize", "run daemonized in the background") { |d|
68
- daemonize = d ? true : false
69
- }
70
-
71
- opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f|
72
- pid = File.expand_path(f)
73
- }
74
-
75
- opts.separator ""
76
- opts.separator "Common options:"
77
-
78
- opts.on_tail("-h", "--help", "Show this message") do
79
- puts opts
80
- exit
81
- end
82
-
83
- opts.on_tail("--version", "Show version") do
84
- puts "Rack #{Rack.version}"
85
- exit
86
- end
87
-
88
- opts.parse! ARGV
89
- }
90
-
91
- require 'pp' if $DEBUG
92
-
93
- config = ARGV[0] || "config.ru"
94
- if !File.exist? config
95
- abort "configuration #{config} not found"
96
- end
97
-
98
- if config =~ /\.ru$/
99
- cfgfile = File.read(config)
100
- if cfgfile[/^#\\(.*)/]
101
- opts.parse! $1.split(/\s+/)
102
- end
103
- inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
104
- nil, config
105
- else
106
- require config
107
- inner_app = Object.const_get(File.basename(config, '.rb').capitalize)
108
- end
109
-
110
- unless server = Rack::Handler.get(server)
111
- # Guess.
112
- if ENV.include?("PHP_FCGI_CHILDREN")
113
- server = Rack::Handler::FastCGI
114
-
115
- # We already speak FastCGI
116
- options.delete :File
117
- options.delete :Port
118
- elsif ENV.include?("REQUEST_METHOD")
119
- server = Rack::Handler::CGI
120
- else
121
- begin
122
- server = Rack::Handler::Mongrel
123
- rescue LoadError => e
124
- server = Rack::Handler::WEBrick
125
- end
126
- end
127
- end
128
-
129
- p server if $DEBUG
130
-
131
- case env
132
- when "development"
133
- app = Rack::Builder.new {
134
- use Rack::CommonLogger, $stderr unless server.name =~ /CGI/
135
- use Rack::ShowExceptions
136
- use Rack::Lint
137
- run inner_app
138
- }.to_app
139
-
140
- when "deployment"
141
- app = Rack::Builder.new {
142
- use Rack::CommonLogger, $stderr unless server.name =~ /CGI/
143
- run inner_app
144
- }.to_app
145
-
146
- when "none"
147
- app = inner_app
148
-
149
- end
150
-
151
- if $DEBUG
152
- pp app
153
- pp inner_app
154
- end
155
-
156
- if daemonize
157
- if RUBY_VERSION < "1.9"
158
- exit if fork
159
- Process.setsid
160
- exit if fork
161
- Dir.chdir "/"
162
- File.umask 0000
163
- STDIN.reopen "/dev/null"
164
- STDOUT.reopen "/dev/null", "a"
165
- STDERR.reopen "/dev/null", "a"
166
- else
167
- Process.daemon
168
- end
169
-
170
- if pid
171
- File.open(pid, 'w'){ |f| f.write("#{Process.pid}") }
172
- at_exit { File.delete(pid) if File.exist?(pid) }
173
- end
174
- end
175
-
176
- server.run app, options
4
+ require "rack"
5
+ Rack::Server.start
data/contrib/rack.png ADDED
Binary file