protocol-rack 0.2.4 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b6a6be852ed5686a4a29416d5e7f308a0b8fecdac08945f7a94c654fe961295
4
- data.tar.gz: e0afd920038faa59a9739eb0780acc7d517d34fdd9bc336c80069c39b06892e4
3
+ metadata.gz: 33a02fca6186127b6390f9189b87c312dd05ec7b3351ad31ca75698a30c82097
4
+ data.tar.gz: d58cafc1f71296ed6d68bf09ceeaf945d8ba1785f701623b0139d8f81adb553d
5
5
  SHA512:
6
- metadata.gz: 6d289be5ff94b209e23de3cb3569cfe76df31356daf072e2caf22ec34e22f3dce6e2e46cc027548b515c83ecd6186c1318f74a1bebaed388618ed7c221b704f4
7
- data.tar.gz: 36c188b1011e436f29fdbf2c317d0c81ed46ae1831a1439cad18248492a005f735d14f2babc5855fd455940018c5f26719978878a697794c17d2d35d1846216d
6
+ metadata.gz: 6460132af99298b1cfb02635af9874050cf6c95c11083a1c6dd5ea884fbe1940d0f3efcea0bfcdbe2040023795bb6ca40046fea8149e55f8c03ca73a76227371
7
+ data.tar.gz: 05ee66f991ad3cd77b4e0937100523c346f2af359ad310591c15286ebccdbad3c01effdb7d79a049aa5f548e595f2c941e69c802e7ed550c75602acf0f48e910
checksums.yaml.gz.sig CHANGED
Binary file
@@ -78,6 +78,12 @@ module Protocol
78
78
  end
79
79
  end
80
80
 
81
+ def make_environment(request)
82
+ {
83
+ request: request
84
+ }
85
+ end
86
+
81
87
  # Build a rack `env` from the incoming request and apply it to the rack middleware.
82
88
  #
83
89
  # @parameter request [Protocol::HTTP::Request] The incoming request.
@@ -86,6 +92,16 @@ module Protocol
86
92
 
87
93
  status, headers, body = @app.call(env)
88
94
 
95
+ # The status must always be an integer.
96
+ unless status.is_a?(Integer)
97
+ raise ArgumentError, "Status must be an integer!"
98
+ end
99
+
100
+ # Headers must always be a hash or equivalent.
101
+ unless headers
102
+ raise ArgumentError, "Headers must not be nil!"
103
+ end
104
+
89
105
  headers, meta = self.wrap_headers(headers)
90
106
 
91
107
  return Response.wrap(env, status, headers, meta, body, request)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  require 'console'
7
7
 
@@ -108,10 +108,12 @@ module Protocol
108
108
 
109
109
  if key.start_with?('rack.')
110
110
  meta[key] = value
111
- else
111
+ elsif value.is_a?(String)
112
112
  value.split("\n").each do |value|
113
113
  headers[key] = value
114
114
  end
115
+ else
116
+ headers[key] = value
115
117
  end
116
118
  end
117
119
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  require 'rack'
7
7
 
@@ -11,7 +11,7 @@ require_relative 'adapter/rack3'
11
11
  module Protocol
12
12
  module Rack
13
13
  module Adapter
14
- if ::Rack::RELEASE >= "3"
14
+ if ::Rack.release >= "3"
15
15
  IMPLEMENTATION = Rack3
16
16
  else
17
17
  IMPLEMENTATION = Rack2
@@ -2,6 +2,7 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022, by Samuel Williams.
5
+ # Copyright, 2023, by Genki Takiuchi.
5
6
 
6
7
  require 'async/io/buffer'
7
8
  require 'protocol/http/body/stream'
@@ -18,6 +19,7 @@ module Protocol
18
19
  # @parameter body [Protocol::HTTP::Body::Readable]
19
20
  def initialize(body)
20
21
  @body = body
22
+ @closed = false
21
23
 
22
24
  # Will hold remaining data in `#read`.
23
25
  @buffer = nil
@@ -46,6 +48,8 @@ module Protocol
46
48
 
47
49
  # Close the input and output bodies.
48
50
  def close(error = nil)
51
+ @closed = true
52
+
49
53
  if @body
50
54
  @body.close(error)
51
55
  @body = nil
@@ -74,7 +78,7 @@ module Protocol
74
78
 
75
79
  # Whether the stream has been closed.
76
80
  def closed?
77
- @body.nil?
81
+ @closed or @body.nil?
78
82
  end
79
83
 
80
84
  # Whether there are any input chunks remaining?
@@ -87,7 +91,7 @@ module Protocol
87
91
  def read_next
88
92
  if @body
89
93
  @body.read
90
- else
94
+ elsif @closed
91
95
  raise IOError, "Stream is not readable, input has been closed!"
92
96
  end
93
97
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  require 'protocol/http/request'
7
7
  require 'protocol/http/headers'
@@ -42,7 +42,7 @@ module Protocol
42
42
 
43
43
  def self.headers(env)
44
44
  headers = ::Protocol::HTTP::Headers.new
45
- env.each do |key, value|
45
+ env.each do |key, value|
46
46
  if key.start_with?('HTTP_')
47
47
  next if key == 'HTTP_HOST'
48
48
  headers[key[5..-1].gsub('_', '-').downcase] = value
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.2.4"
8
+ VERSION = "0.2.6"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2022, by Samuel Williams.
3
+ Copyright, 2022-2023, by Samuel Williams.
4
+ Copyright, 2023, by Genki Takiuchi.
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Genki Takiuchi
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain:
@@ -37,7 +38,7 @@ cert_chain:
37
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
40
  -----END CERTIFICATE-----
40
- date: 2022-09-06 00:00:00.000000000 Z
41
+ date: 2023-06-11 00:00:00.000000000 Z
41
42
  dependencies:
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: protocol-http
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  - !ruby/object:Gem::Version
194
195
  version: '0'
195
196
  requirements: []
196
- rubygems_version: 3.3.7
197
+ rubygems_version: 3.4.7
197
198
  signing_key:
198
199
  specification_version: 4
199
200
  summary: An implementation of the Rack protocol/specification.
metadata.gz.sig CHANGED
Binary file