protocol-rack 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f7becb7e22562224a7b79eeaa6776b2132f5b5261a51aba1ac9e75e56dcc038
4
- data.tar.gz: 333f072f05e98e6e52662294e41387cfdf1e59b9217990d42bb6694c241ed427
3
+ metadata.gz: 93f36e89bf961a77ffb20daa447e04e07d019e213d477c35383c8195f0dff9b4
4
+ data.tar.gz: cd60bb47a4d8e04b5505e339df964237efc00de093783b3179c8421c33eabcc3
5
5
  SHA512:
6
- metadata.gz: 881510d4b665e3d9b6ef041eedeb27732601294a8d0e45c43900a8ef8cc11556fcff164c900aa0444272ba6e81cca1716a619b1520996ee411b842d166c5065f
7
- data.tar.gz: e64f1f3c7ce42aa4a829bce8e1d9c4c270bb4fe5ecc99f6d01ae69222d3a18440f1e3ce83b2b50e842e7fd49b9c28d74383e6b9df8f9d6aa01e6afe564fe6019
6
+ metadata.gz: 4e25a07fa07b2e41fc19a48d331311db49ddd19f87faa26ffc523285081a64ba2fc94e9a9d480c0f86e1f78a9bc883f8e45a2239b372ada59df2e9a11682500e
7
+ data.tar.gz: a96d427f73445ee5e449ca0f80bf2bd396cc7737fc2b97fb5704143cbe5b2325a663403197cf51d807b77d89bcf62bbab36bc965241661be19a942dab08582c2
checksums.yaml.gz.sig CHANGED
Binary file
@@ -73,6 +73,30 @@ module Protocol
73
73
  return env
74
74
  end
75
75
 
76
+ # Build a rack `env` from the incoming request and apply it to the rack middleware.
77
+ #
78
+ # @parameter request [Protocol::HTTP::Request] The incoming request.
79
+ def call(request)
80
+ env = self.make_environment(request)
81
+
82
+ status, headers, body = @app.call(env)
83
+
84
+ headers, meta = self.wrap_headers(headers)
85
+
86
+ # Rack 2 spec does not allow only partial hijacking.
87
+ # if hijack_body = meta[RACK_HIJACK]
88
+ # body = hijack_body
89
+ # end
90
+
91
+ return Response.wrap(env, status, headers, meta, body, request)
92
+ rescue => exception
93
+ Console.logger.error(self) {exception}
94
+
95
+ body&.close if body.respond_to?(:close)
96
+
97
+ return failure_response(exception)
98
+ end
99
+
76
100
  # Process the rack response headers into into a {Protocol::HTTP::Headers} instance, along with any extra `rack.` metadata.
77
101
  # @returns [Tuple(Protocol::HTTP::Headers, Hash)]
78
102
  def wrap_headers(fields)
@@ -14,41 +14,47 @@ module Protocol
14
14
  def initialize(block, input = nil)
15
15
  @block = block
16
16
  @input = input
17
+ @output = nil
17
18
  end
18
19
 
19
20
  attr :block
20
-
21
- def each(&block)
22
- stream = ::Protocol::HTTP::Body::Stream.new(@input, Output.new(block))
23
-
24
- @block.call(stream)
25
- end
26
-
27
- def stream?
28
- true
29
- end
30
-
31
- def call(stream)
32
- @block.call(stream)
33
- end
34
21
 
35
22
  class Output
36
- def initialize(block)
37
- @block = block
23
+ def initialize(input, block)
24
+ stream = ::Protocol::HTTP::Body::Stream.new(input, self)
25
+ @fiber = Fiber.new do
26
+ block.call(stream)
27
+ @fiber = nil
28
+ end
38
29
  end
39
30
 
40
31
  def write(chunk)
41
- @block.call(chunk)
32
+ Fiber.yield(chunk)
42
33
  end
43
34
 
44
35
  def close
45
- @block = nil
36
+ @fiber = nil
46
37
  end
47
38
 
48
- def empty?
49
- true
39
+ def read
40
+ @fiber&.resume
50
41
  end
51
42
  end
43
+
44
+ # Invokes the block in a fiber which yields chunks when they are available.
45
+ def read
46
+ @output ||= Output.new(@input, @block)
47
+ return @output.read
48
+ end
49
+
50
+ def stream?
51
+ true
52
+ end
53
+
54
+ def call(stream)
55
+ raise "Streaming body has already been read!" if @output
56
+ @block.call(stream)
57
+ end
52
58
  end
53
59
  end
54
60
  end
@@ -46,6 +46,10 @@ module Protocol
46
46
  Console.logger.warn(self, "Ignoring protocol-level headers: #{ignored.inspect}")
47
47
  end
48
48
 
49
+ if hijack_body = meta['rack.hijack']
50
+ body = hijack_body
51
+ end
52
+
49
53
  body = Body.wrap(env, status, headers, body, request&.body)
50
54
 
51
55
  if request&.head?
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.2.0"
8
+ VERSION = "0.2.3"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2022-08-27 00:00:00.000000000 Z
40
+ date: 2022-08-31 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: protocol-http
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 0.23.4
48
+ version: '0.23'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 0.23.4
55
+ version: '0.23'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rack
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -85,72 +85,72 @@ dependencies:
85
85
  name: bake-test
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">="
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '0'
90
+ version: '0.1'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0'
97
+ version: '0.1'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: bake-test-external
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: '0.1'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: '0.1'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: covered
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: '0.16'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: '0.16'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: sus
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: 0.11.0
132
+ version: '0.12'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: 0.11.0
139
+ version: '0.12'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: sus-fixtures-async-http
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: 0.1.1
146
+ version: '0.1'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: 0.1.1
153
+ version: '0.1'
154
154
  description:
155
155
  email:
156
156
  executables: []
metadata.gz.sig CHANGED
Binary file