cloud_events 0.3.1 → 0.4.0
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
- data/CHANGELOG.md +6 -0
- data/lib/cloud_events/content_type.rb +4 -2
- data/lib/cloud_events/http_binding.rb +22 -5
- data/lib/cloud_events/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae042efe6c2ccd066620bf2e4f548d6f0470fff3426e92442e5f403c8e06273a
|
4
|
+
data.tar.gz: f8d1fbbb00faa1d2b72db8c1e9ac016580951884e78cc6129eeec7fb8d844d5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a156c8448d1c7b59ef683e90ecba1d22dfbe4564574a9355ee110c31f91240137295c437933ed6038fe8e1a9e9e5b19067ef82ee11affd38c6c2f41dac2b50
|
7
|
+
data.tar.gz: 9d8b7c3745261e6addd427b9b4d24b3873014f998f0f0844889315a6ea59ab3c11e44cbc25abfdffdb758357545c8c62eeca4f5d5138e6bd2179d700e1dd60c6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v0.4.0 / 2021-05-26
|
4
|
+
|
5
|
+
* ADDED: ContentType can take an optional default charset
|
6
|
+
* FIXED: Binary HTTP format parses quoted tokens according to RFC 7230 section 3.2.6
|
7
|
+
* FIXED: When encoding structured events for HTTP transport, the content-type now includes the charset
|
8
|
+
|
3
9
|
### v0.3.1 / 2021-04-25
|
4
10
|
|
5
11
|
* FIXED: Fixed exception when decoding from a rack source that uses InputWrapper
|
@@ -21,14 +21,16 @@ module CloudEvents
|
|
21
21
|
# Parse the given header value.
|
22
22
|
#
|
23
23
|
# @param string [String] Content-Type header value in RFC 2045 format
|
24
|
+
# @param default_charset [String] Optional. The charset to use if none is
|
25
|
+
# specified. Defaults to `us-ascii`.
|
24
26
|
#
|
25
|
-
def initialize string
|
27
|
+
def initialize string, default_charset: nil
|
26
28
|
@string = string
|
27
29
|
@media_type = "text"
|
28
30
|
@subtype_base = @subtype = "plain"
|
29
31
|
@subtype_format = nil
|
30
32
|
@params = []
|
31
|
-
@charset = "us-ascii"
|
33
|
+
@charset = default_charset || "us-ascii"
|
32
34
|
@error_message = nil
|
33
35
|
parse consume_comments string.strip
|
34
36
|
@canonical_string = "#{@media_type}/#{@subtype}" +
|
@@ -183,7 +183,10 @@ module CloudEvents
|
|
183
183
|
handlers = @structured_formatters[format] || []
|
184
184
|
handlers.reverse_each do |handler|
|
185
185
|
content = handler.encode event, **format_args
|
186
|
-
|
186
|
+
if content
|
187
|
+
content_type = "application/cloudevents+#{format}; charset=#{charset_of content}"
|
188
|
+
return [{ "Content-Type" => content_type }, content]
|
189
|
+
end
|
187
190
|
end
|
188
191
|
raise HttpContentError, "Unknown cloudevents format: #{format.inspect}"
|
189
192
|
end
|
@@ -206,7 +209,10 @@ module CloudEvents
|
|
206
209
|
handlers = @batched_formatters[format] || []
|
207
210
|
handlers.reverse_each do |handler|
|
208
211
|
content = handler.encode_batch events, **format_args
|
209
|
-
|
212
|
+
if content
|
213
|
+
content_type = "application/cloudevents-batch+#{format}; charset=#{charset_of content}"
|
214
|
+
return [{ "Content-Type" => content_type }, content]
|
215
|
+
end
|
210
216
|
end
|
211
217
|
raise HttpContentError, "Unknown cloudevents format: #{format.inspect}"
|
212
218
|
end
|
@@ -254,6 +260,7 @@ module CloudEvents
|
|
254
260
|
# @return [String] Resulting decoded string in UTF-8.
|
255
261
|
#
|
256
262
|
def percent_decode str
|
263
|
+
str = str.gsub(/"((?:[^"\\]|\\.)*)"/) { ::Regexp.last_match(1).gsub(/\\(.)/, '\1') }
|
257
264
|
decoded_str = str.gsub(/%[0-9a-fA-F]{2}/) { |m| [m[1..-1].to_i(16)].pack "C" }
|
258
265
|
decoded_str.force_encoding ::Encoding::UTF_8
|
259
266
|
end
|
@@ -271,7 +278,7 @@ module CloudEvents
|
|
271
278
|
arr = []
|
272
279
|
utf_str = str.to_s.encode ::Encoding::UTF_8
|
273
280
|
utf_str.each_byte do |byte|
|
274
|
-
if byte >= 33 && byte <= 126 && byte != 37
|
281
|
+
if byte >= 33 && byte <= 126 && byte != 34 && byte != 37
|
275
282
|
arr << byte
|
276
283
|
else
|
277
284
|
hi = byte / 16
|
@@ -292,18 +299,28 @@ module CloudEvents
|
|
292
299
|
begin
|
293
300
|
str.force_encoding charset
|
294
301
|
rescue ::ArgumentError
|
295
|
-
#
|
302
|
+
# Use binary for now if the charset is unrecognized
|
303
|
+
str.force_encoding ::Encoding::ASCII_8BIT
|
296
304
|
end
|
297
305
|
end
|
298
306
|
str
|
299
307
|
end
|
300
308
|
|
301
309
|
def string_content_type str
|
302
|
-
if str.encoding == ::Encoding
|
310
|
+
if str.encoding == ::Encoding::ASCII_8BIT
|
303
311
|
"application/octet-stream"
|
304
312
|
else
|
305
313
|
"text/plain; charset=#{str.encoding.name.downcase}"
|
306
314
|
end
|
307
315
|
end
|
316
|
+
|
317
|
+
def charset_of str
|
318
|
+
encoding = str.encoding
|
319
|
+
if encoding == ::Encoding::ASCII_8BIT
|
320
|
+
"binary"
|
321
|
+
else
|
322
|
+
encoding.name.downcase
|
323
|
+
end
|
324
|
+
end
|
308
325
|
end
|
309
326
|
end
|
data/lib/cloud_events/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The official Ruby implementation of the CloudEvents Specification. Provides
|
14
14
|
data types for events, and HTTP/JSON bindings for marshalling and unmarshalling
|
@@ -38,10 +38,10 @@ homepage: https://github.com/cloudevents/sdk-ruby
|
|
38
38
|
licenses:
|
39
39
|
- Apache-2.0
|
40
40
|
metadata:
|
41
|
-
changelog_uri: https://cloudevents.github.io/sdk-ruby/v0.
|
41
|
+
changelog_uri: https://cloudevents.github.io/sdk-ruby/v0.4.0/file.CHANGELOG.html
|
42
42
|
source_code_uri: https://github.com/cloudevents/sdk-ruby
|
43
43
|
bug_tracker_uri: https://github.com/cloudevents/sdk-ruby/issues
|
44
|
-
documentation_uri: https://cloudevents.github.io/sdk-ruby/v0.
|
44
|
+
documentation_uri: https://cloudevents.github.io/sdk-ruby/v0.4.0
|
45
45
|
post_install_message:
|
46
46
|
rdoc_options: []
|
47
47
|
require_paths:
|