rack 2.2.10 → 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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +138 -105
  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/basic.rb +2 -1
  13. data/lib/rack/auth/digest/md5.rb +1 -131
  14. data/lib/rack/auth/digest/nonce.rb +1 -53
  15. data/lib/rack/auth/digest/params.rb +1 -54
  16. data/lib/rack/auth/digest/request.rb +1 -43
  17. data/lib/rack/auth/digest.rb +256 -0
  18. data/lib/rack/body_proxy.rb +3 -1
  19. data/lib/rack/builder.rb +60 -42
  20. data/lib/rack/cascade.rb +2 -0
  21. data/lib/rack/chunked.rb +16 -13
  22. data/lib/rack/common_logger.rb +23 -18
  23. data/lib/rack/conditional_get.rb +18 -15
  24. data/lib/rack/constants.rb +62 -0
  25. data/lib/rack/content_length.rb +12 -16
  26. data/lib/rack/content_type.rb +8 -5
  27. data/lib/rack/deflater.rb +40 -26
  28. data/lib/rack/directory.rb +9 -3
  29. data/lib/rack/etag.rb +14 -23
  30. data/lib/rack/events.rb +4 -0
  31. data/lib/rack/file.rb +2 -0
  32. data/lib/rack/files.rb +15 -17
  33. data/lib/rack/head.rb +9 -8
  34. data/lib/rack/headers.rb +154 -0
  35. data/lib/rack/lint.rb +740 -649
  36. data/lib/rack/lock.rb +2 -5
  37. data/lib/rack/logger.rb +2 -0
  38. data/lib/rack/media_type.rb +4 -9
  39. data/lib/rack/method_override.rb +5 -1
  40. data/lib/rack/mime.rb +8 -0
  41. data/lib/rack/mock.rb +1 -271
  42. data/lib/rack/mock_request.rb +166 -0
  43. data/lib/rack/mock_response.rb +124 -0
  44. data/lib/rack/multipart/generator.rb +7 -5
  45. data/lib/rack/multipart/parser.rb +123 -85
  46. data/lib/rack/multipart/uploaded_file.rb +4 -0
  47. data/lib/rack/multipart.rb +20 -40
  48. data/lib/rack/null_logger.rb +9 -0
  49. data/lib/rack/query_parser.rb +76 -44
  50. data/lib/rack/recursive.rb +2 -0
  51. data/lib/rack/reloader.rb +0 -2
  52. data/lib/rack/request.rb +189 -91
  53. data/lib/rack/response.rb +131 -61
  54. data/lib/rack/rewindable_input.rb +24 -5
  55. data/lib/rack/runtime.rb +7 -6
  56. data/lib/rack/sendfile.rb +30 -25
  57. data/lib/rack/show_exceptions.rb +15 -2
  58. data/lib/rack/show_status.rb +17 -7
  59. data/lib/rack/static.rb +8 -8
  60. data/lib/rack/tempfile_reaper.rb +15 -4
  61. data/lib/rack/urlmap.rb +4 -2
  62. data/lib/rack/utils.rb +212 -202
  63. data/lib/rack/version.rb +9 -4
  64. data/lib/rack.rb +5 -76
  65. data/rack.gemspec +6 -6
  66. metadata +19 -31
  67. data/README.rdoc +0 -320
  68. data/bin/rackup +0 -5
  69. data/contrib/rack.png +0 -0
  70. data/contrib/rack.svg +0 -150
  71. data/contrib/rack_logo.svg +0 -164
  72. data/lib/rack/core_ext/regexp.rb +0 -14
  73. data/lib/rack/handler/cgi.rb +0 -59
  74. data/lib/rack/handler/fastcgi.rb +0 -100
  75. data/lib/rack/handler/lsws.rb +0 -61
  76. data/lib/rack/handler/scgi.rb +0 -71
  77. data/lib/rack/handler/thin.rb +0 -36
  78. data/lib/rack/handler/webrick.rb +0 -129
  79. data/lib/rack/handler.rb +0 -104
  80. data/lib/rack/lobster.rb +0 -70
  81. data/lib/rack/server.rb +0 -466
  82. data/lib/rack/session/abstract/id.rb +0 -523
  83. data/lib/rack/session/cookie.rb +0 -203
  84. data/lib/rack/session/memcache.rb +0 -10
  85. data/lib/rack/session/pool.rb +0 -85
data/lib/rack/head.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'constants'
4
+ require_relative 'body_proxy'
5
+
3
6
  module Rack
4
7
  # Rack::Head returns an empty body for all HEAD requests. It leaves
5
8
  # all other requests unchanged.
@@ -9,17 +12,15 @@ module Rack
9
12
  end
10
13
 
11
14
  def call(env)
12
- status, headers, body = @app.call(env)
15
+ _, _, body = response = @app.call(env)
13
16
 
14
17
  if env[REQUEST_METHOD] == HEAD
15
- [
16
- status, headers, Rack::BodyProxy.new([]) do
17
- body.close if body.respond_to? :close
18
- end
19
- ]
20
- else
21
- [status, headers, body]
18
+ response[2] = Rack::BodyProxy.new([]) do
19
+ body.close if body.respond_to? :close
20
+ end
22
21
  end
22
+
23
+ response
23
24
  end
24
25
  end
25
26
  end
@@ -0,0 +1,154 @@
1
+ module Rack
2
+ # Rack::Headers is a Hash subclass that downcases all keys. It's designed
3
+ # to be used by rack applications that don't implement the Rack 3 SPEC
4
+ # (by using non-lowercase response header keys), automatically handling
5
+ # the downcasing of keys.
6
+ class Headers < Hash
7
+ def self.[](*items)
8
+ if items.length % 2 != 0
9
+ if items.length == 1 && items.first.is_a?(Hash)
10
+ new.merge!(items.first)
11
+ else
12
+ raise ArgumentError, "odd number of arguments for Rack::Headers"
13
+ end
14
+ else
15
+ hash = new
16
+ loop do
17
+ break if items.length == 0
18
+ key = items.shift
19
+ value = items.shift
20
+ hash[key] = value
21
+ end
22
+ hash
23
+ end
24
+ end
25
+
26
+ def [](key)
27
+ super(downcase_key(key))
28
+ end
29
+
30
+ def []=(key, value)
31
+ super(key.downcase.freeze, value)
32
+ end
33
+ alias store []=
34
+
35
+ def assoc(key)
36
+ super(downcase_key(key))
37
+ end
38
+
39
+ def compare_by_identity
40
+ raise TypeError, "Rack::Headers cannot compare by identity, use regular Hash"
41
+ end
42
+
43
+ def delete(key)
44
+ super(downcase_key(key))
45
+ end
46
+
47
+ def dig(key, *a)
48
+ super(downcase_key(key), *a)
49
+ end
50
+
51
+ def fetch(key, *default, &block)
52
+ key = downcase_key(key)
53
+ super
54
+ end
55
+
56
+ def fetch_values(*a)
57
+ super(*a.map!{|key| downcase_key(key)})
58
+ end
59
+
60
+ def has_key?(key)
61
+ super(downcase_key(key))
62
+ end
63
+ alias include? has_key?
64
+ alias key? has_key?
65
+ alias member? has_key?
66
+
67
+ def invert
68
+ hash = self.class.new
69
+ each{|key, value| hash[value] = key}
70
+ hash
71
+ end
72
+
73
+ def merge(hash, &block)
74
+ dup.merge!(hash, &block)
75
+ end
76
+
77
+ def reject(&block)
78
+ hash = dup
79
+ hash.reject!(&block)
80
+ hash
81
+ end
82
+
83
+ def replace(hash)
84
+ clear
85
+ update(hash)
86
+ end
87
+
88
+ def select(&block)
89
+ hash = dup
90
+ hash.select!(&block)
91
+ hash
92
+ end
93
+
94
+ def to_proc
95
+ lambda{|x| self[x]}
96
+ end
97
+
98
+ def transform_values(&block)
99
+ dup.transform_values!(&block)
100
+ end
101
+
102
+ def update(hash, &block)
103
+ hash.each do |key, value|
104
+ self[key] = if block_given? && include?(key)
105
+ block.call(key, self[key], value)
106
+ else
107
+ value
108
+ end
109
+ end
110
+ self
111
+ end
112
+ alias merge! update
113
+
114
+ def values_at(*keys)
115
+ keys.map{|key| self[key]}
116
+ end
117
+
118
+ # :nocov:
119
+ if RUBY_VERSION >= '2.5'
120
+ # :nocov:
121
+ def slice(*a)
122
+ h = self.class.new
123
+ a.each{|k| h[k] = self[k] if has_key?(k)}
124
+ h
125
+ end
126
+
127
+ def transform_keys(&block)
128
+ dup.transform_keys!(&block)
129
+ end
130
+
131
+ def transform_keys!
132
+ hash = self.class.new
133
+ each do |k, v|
134
+ hash[yield k] = v
135
+ end
136
+ replace(hash)
137
+ end
138
+ end
139
+
140
+ # :nocov:
141
+ if RUBY_VERSION >= '3.0'
142
+ # :nocov:
143
+ def except(*a)
144
+ super(*a.map!{|key| downcase_key(key)})
145
+ end
146
+ end
147
+
148
+ private
149
+
150
+ def downcase_key(key)
151
+ key.is_a?(String) ? key.downcase : key
152
+ end
153
+ end
154
+ end