rack 3.0.11 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +59 -4
- data/CONTRIBUTING.md +11 -9
- data/README.md +34 -15
- data/SPEC.rdoc +38 -13
- data/lib/rack/auth/basic.rb +1 -2
- data/lib/rack/bad_request.rb +8 -0
- data/lib/rack/builder.rb +23 -10
- data/lib/rack/cascade.rb +0 -3
- data/lib/rack/constants.rb +3 -1
- data/lib/rack/content_length.rb +0 -1
- data/lib/rack/headers.rb +86 -2
- data/lib/rack/lint.rb +116 -34
- data/lib/rack/logger.rb +2 -1
- data/lib/rack/mime.rb +6 -5
- data/lib/rack/mock_request.rb +19 -14
- data/lib/rack/mock_response.rb +12 -14
- data/lib/rack/multipart/parser.rb +123 -62
- data/lib/rack/multipart.rb +34 -1
- data/lib/rack/query_parser.rb +15 -68
- data/lib/rack/request.rb +28 -21
- data/lib/rack/response.rb +21 -23
- data/lib/rack/show_exceptions.rb +6 -2
- data/lib/rack/utils.rb +57 -96
- data/lib/rack/version.rb +1 -14
- data/lib/rack.rb +10 -16
- metadata +4 -10
- data/lib/rack/auth/digest/md5.rb +0 -1
- data/lib/rack/auth/digest/nonce.rb +0 -1
- data/lib/rack/auth/digest/params.rb +0 -1
- data/lib/rack/auth/digest/request.rb +0 -1
- data/lib/rack/auth/digest.rb +0 -256
- data/lib/rack/chunked.rb +0 -120
- data/lib/rack/file.rb +0 -9
data/lib/rack/chunked.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'constants'
|
4
|
-
require_relative 'utils'
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
warn "Rack::Chunked is deprecated and will be removed in Rack 3.1", uplevel: 1
|
8
|
-
|
9
|
-
# Middleware that applies chunked transfer encoding to response bodies
|
10
|
-
# when the response does not include a content-length header.
|
11
|
-
#
|
12
|
-
# This supports the trailer response header to allow the use of trailing
|
13
|
-
# headers in the chunked encoding. However, using this requires you manually
|
14
|
-
# specify a response body that supports a +trailers+ method. Example:
|
15
|
-
#
|
16
|
-
# [200, { 'trailer' => 'expires'}, ["Hello", "World"]]
|
17
|
-
# # error raised
|
18
|
-
#
|
19
|
-
# body = ["Hello", "World"]
|
20
|
-
# def body.trailers
|
21
|
-
# { 'expires' => Time.now.to_s }
|
22
|
-
# end
|
23
|
-
# [200, { 'trailer' => 'expires'}, body]
|
24
|
-
# # No exception raised
|
25
|
-
class Chunked
|
26
|
-
include Rack::Utils
|
27
|
-
|
28
|
-
# A body wrapper that emits chunked responses.
|
29
|
-
class Body
|
30
|
-
TERM = "\r\n"
|
31
|
-
TAIL = "0#{TERM}"
|
32
|
-
|
33
|
-
# Store the response body to be chunked.
|
34
|
-
def initialize(body)
|
35
|
-
@body = body
|
36
|
-
end
|
37
|
-
|
38
|
-
# For each element yielded by the response body, yield
|
39
|
-
# the element in chunked encoding.
|
40
|
-
def each(&block)
|
41
|
-
term = TERM
|
42
|
-
@body.each do |chunk|
|
43
|
-
size = chunk.bytesize
|
44
|
-
next if size == 0
|
45
|
-
|
46
|
-
yield [size.to_s(16), term, chunk.b, term].join
|
47
|
-
end
|
48
|
-
yield TAIL
|
49
|
-
yield_trailers(&block)
|
50
|
-
yield term
|
51
|
-
end
|
52
|
-
|
53
|
-
# Close the response body if the response body supports it.
|
54
|
-
def close
|
55
|
-
@body.close if @body.respond_to?(:close)
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
# Do nothing as this class does not support trailer headers.
|
61
|
-
def yield_trailers
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# A body wrapper that emits chunked responses and also supports
|
66
|
-
# sending Trailer headers. Note that the response body provided to
|
67
|
-
# initialize must have a +trailers+ method that returns a hash
|
68
|
-
# of trailer headers, and the rack response itself should have a
|
69
|
-
# Trailer header listing the headers that the +trailers+ method
|
70
|
-
# will return.
|
71
|
-
class TrailerBody < Body
|
72
|
-
private
|
73
|
-
|
74
|
-
# Yield strings for each trailer header.
|
75
|
-
def yield_trailers
|
76
|
-
@body.trailers.each_pair do |k, v|
|
77
|
-
yield "#{k}: #{v}\r\n"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def initialize(app)
|
83
|
-
@app = app
|
84
|
-
end
|
85
|
-
|
86
|
-
# Whether the HTTP version supports chunked encoding (HTTP 1.1 does).
|
87
|
-
def chunkable_version?(ver)
|
88
|
-
case ver
|
89
|
-
# pre-HTTP/1.0 (informally "HTTP/0.9") HTTP requests did not have
|
90
|
-
# a version (nor response headers)
|
91
|
-
when 'HTTP/1.0', nil, 'HTTP/0.9'
|
92
|
-
false
|
93
|
-
else
|
94
|
-
true
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# If the rack app returns a response that should have a body,
|
99
|
-
# but does not have content-length or transfer-encoding headers,
|
100
|
-
# modify the response to use chunked transfer-encoding.
|
101
|
-
def call(env)
|
102
|
-
status, headers, body = response = @app.call(env)
|
103
|
-
|
104
|
-
if chunkable_version?(env[SERVER_PROTOCOL]) &&
|
105
|
-
!STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) &&
|
106
|
-
!headers[CONTENT_LENGTH] &&
|
107
|
-
!headers[TRANSFER_ENCODING]
|
108
|
-
|
109
|
-
headers[TRANSFER_ENCODING] = 'chunked'
|
110
|
-
if headers['trailer']
|
111
|
-
response[2] = TrailerBody.new(body)
|
112
|
-
else
|
113
|
-
response[2] = Body.new(body)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
response
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|