protocol-rack 0.1.3 → 0.1.6
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/rack/adapter/generic.rb +3 -1
- data/lib/protocol/rack/adapter/rack2.rb +28 -1
- data/lib/protocol/rack/adapter/rack3.rb +23 -0
- data/lib/protocol/rack/input.rb +7 -19
- data/lib/protocol/rack/request.rb +1 -0
- data/lib/protocol/rack/response.rb +2 -26
- data/lib/protocol/rack/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2826bd60593f65a9f2f5350e714c2436b266b9d393d8afb594e59d18ab9168f9
|
4
|
+
data.tar.gz: 4c5051edaf485a0413d5090641c6347ead593a3b5210fcb9b2538808218d7a63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9fa485dd38739b5ff6a400cf047f7dd24237211b9e092252f927ea6bda819f383b08b8dc44be434cf4d44a1828661542aaa60058cac56d8d49c376355bb0ef
|
7
|
+
data.tar.gz: f2a4c166cf5466f230a4cbdf0b1e221d328d06462dee18a7c2d6951ced7530e58528519f5627ee3905449bb4e53cd7dfd563f5f6606a7e93511df1daac5867ba
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -103,7 +103,9 @@ module Protocol
|
|
103
103
|
|
104
104
|
status, headers, body = @app.call(env)
|
105
105
|
|
106
|
-
|
106
|
+
headers, meta = self.wrap_headers(headers)
|
107
|
+
|
108
|
+
return Response.wrap(status, headers, meta, body, request)
|
107
109
|
rescue => exception
|
108
110
|
Console.logger.error(self) {exception}
|
109
111
|
|
@@ -90,11 +90,34 @@ module Protocol
|
|
90
90
|
return env
|
91
91
|
end
|
92
92
|
|
93
|
+
# Process the rack response headers into into a {Protocol::HTTP::Headers} instance, along with any extra `rack.` metadata.
|
94
|
+
# @returns [Tuple(Protocol::HTTP::Headers, Hash)]
|
95
|
+
def wrap_headers(fields)
|
96
|
+
headers = ::Protocol::HTTP::Headers.new
|
97
|
+
meta = {}
|
98
|
+
|
99
|
+
fields.each do |key, value|
|
100
|
+
key = key.downcase
|
101
|
+
|
102
|
+
if key.start_with?('rack.')
|
103
|
+
meta[key] = value
|
104
|
+
else
|
105
|
+
value.split("\n").each do |value|
|
106
|
+
headers[key] = value
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
return headers, meta
|
112
|
+
end
|
113
|
+
|
93
114
|
def self.make_response(env, response)
|
94
115
|
# These interfaces should be largely compatible:
|
95
116
|
headers = response.headers.to_h
|
117
|
+
|
96
118
|
if protocol = response.protocol
|
97
119
|
headers['rack.protocol'] = protocol
|
120
|
+
# headers['upgrade'] = protocol
|
98
121
|
end
|
99
122
|
|
100
123
|
if body = response.body and body.stream?
|
@@ -103,7 +126,11 @@ module Protocol
|
|
103
126
|
body = []
|
104
127
|
end
|
105
128
|
end
|
106
|
-
|
129
|
+
|
130
|
+
headers.transform_values! do |value|
|
131
|
+
value.is_a?(Array) ? value.join("\n") : value
|
132
|
+
end
|
133
|
+
|
107
134
|
[response.status, headers, body]
|
108
135
|
end
|
109
136
|
end
|
@@ -76,6 +76,29 @@ module Protocol
|
|
76
76
|
return env
|
77
77
|
end
|
78
78
|
|
79
|
+
# Process the rack response headers into into a {Protocol::HTTP::Headers} instance, along with any extra `rack.` metadata.
|
80
|
+
# @returns [Tuple(Protocol::HTTP::Headers, Hash)]
|
81
|
+
def wrap_headers(fields)
|
82
|
+
headers = ::Protocol::HTTP::Headers.new
|
83
|
+
meta = {}
|
84
|
+
|
85
|
+
fields.each do |key, value|
|
86
|
+
key = key.downcase
|
87
|
+
|
88
|
+
if key.start_with?('rack.')
|
89
|
+
meta[key] = value
|
90
|
+
elsif value.is_a?(Array)
|
91
|
+
value.each do |value|
|
92
|
+
headers[key] = value
|
93
|
+
end
|
94
|
+
else
|
95
|
+
headers[key] = value
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
return headers, meta
|
100
|
+
end
|
101
|
+
|
79
102
|
def self.make_response(env, response)
|
80
103
|
# These interfaces should be largely compatible:
|
81
104
|
headers = response.headers.to_h
|
data/lib/protocol/rack/input.rb
CHANGED
@@ -44,34 +44,23 @@ module Protocol
|
|
44
44
|
# @attribute [Protocol::HTTP::Body::Readable]
|
45
45
|
attr :body
|
46
46
|
|
47
|
+
include Protocol::HTTP::Body::Stream::Reader
|
48
|
+
|
49
|
+
alias gets read_partial
|
50
|
+
|
47
51
|
# Enumerate chunks of the request body.
|
48
52
|
# @yields {|chunk| ...}
|
49
53
|
# @parameter chunk [String]
|
50
54
|
def each(&block)
|
51
55
|
return to_enum unless block_given?
|
52
56
|
|
53
|
-
|
57
|
+
return if closed?
|
58
|
+
|
59
|
+
while chunk = read_partial
|
54
60
|
yield chunk
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
|
-
include Protocol::HTTP::Body::Stream::Reader
|
59
|
-
|
60
|
-
# Read the next chunk of data from the input stream.
|
61
|
-
#
|
62
|
-
# `gets` must be called without arguments and return a `String`, or `nil` when the input stream has no more data.
|
63
|
-
#
|
64
|
-
# @returns [String | Nil] The next chunk from the body.
|
65
|
-
def gets
|
66
|
-
if @buffer.nil?
|
67
|
-
return read_next
|
68
|
-
else
|
69
|
-
buffer = @buffer
|
70
|
-
@buffer = nil
|
71
|
-
return buffer
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
64
|
# Close the input and output bodies.
|
76
65
|
def close(error = nil)
|
77
66
|
if @body
|
@@ -116,7 +105,6 @@ module Protocol
|
|
116
105
|
if @body
|
117
106
|
@body.read
|
118
107
|
else
|
119
|
-
@body = nil
|
120
108
|
raise IOError, "Stream is not readable, input has been closed!"
|
121
109
|
end
|
122
110
|
end
|
@@ -51,38 +51,14 @@ module Protocol
|
|
51
51
|
'upgrade',
|
52
52
|
]
|
53
53
|
|
54
|
-
# Process the rack response headers into into a {Protocol::HTTP::Headers} instance, along with any extra `rack.` metadata.
|
55
|
-
# @returns [Tuple(Protocol::HTTP::Headers, Hash)]
|
56
|
-
def self.wrap_headers(fields)
|
57
|
-
headers = ::Protocol::HTTP::Headers.new
|
58
|
-
meta = {}
|
59
|
-
|
60
|
-
fields.each do |key, value|
|
61
|
-
key = key.downcase
|
62
|
-
|
63
|
-
if key.start_with?('rack.')
|
64
|
-
meta[key] = value
|
65
|
-
elsif value.is_a?(Array)
|
66
|
-
value.each do |value|
|
67
|
-
headers[key] = value
|
68
|
-
end
|
69
|
-
else
|
70
|
-
headers[key] = value
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
return headers, meta
|
75
|
-
end
|
76
|
-
|
77
54
|
# Wrap a rack response.
|
78
55
|
# @parameter status [Integer] The rack response status.
|
79
56
|
# @parameter headers [Duck(:each)] The rack response headers.
|
80
57
|
# @parameter body [Duck(:each, :close) | Nil] The rack response body.
|
81
58
|
# @parameter request [Protocol::HTTP::Request] The original request.
|
82
|
-
def self.wrap(status, headers, body, request = nil)
|
83
|
-
headers, meta = wrap_headers(headers)
|
84
|
-
|
59
|
+
def self.wrap(status, headers, meta, body, request = nil)
|
85
60
|
ignored = headers.extract(HOP_HEADERS)
|
61
|
+
|
86
62
|
unless ignored.empty?
|
87
63
|
Console.logger.warn(self, "Ignoring protocol-level headers: #{ignored.inspect}")
|
88
64
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|