protocol-http 0.46.0 → 0.47.1

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: 753df89051cc0eeff1cab5100a4ebc2a98e11bd3dce4a3fbcba890406c198c32
4
- data.tar.gz: dbc6b80efe3fc8a430839868f160151a9490336cc39423e31cfd851076b72947
3
+ metadata.gz: d8281f44eb94360f117cba9ef4770386d57b72049ec2200e45041f7b93193147
4
+ data.tar.gz: 0e93ed313a1a91971568b575b58db52857f15da6a92fe8764294f2b6ef2335c6
5
5
  SHA512:
6
- metadata.gz: 104b449c9a3beaaf7f3c50e28eb21df3f2bef95b89ec954bd20a808a09b508f69d8e0387d6b41ed8e7dc02e41a85bc1116ff8f775694c4e0b26c3899b248f310
7
- data.tar.gz: 3ea2e87c3375055aa89f8d9b73b549854cb53ecb90bf6ee3f75ffc4c4ae8b7fbb61b10119fbdb0d125287aea03c894c7327b79ee410d28a771faab24e2fcafa5
6
+ metadata.gz: 4f5765e41ef7706b20f8c82812099dc5e79fa6f5c9036332688e5dde9ea0a41a52d44a2442aa33d3514f977939f70c32b40fa858179d4bada70df5b70227e7ab
7
+ data.tar.gz: 8835f1c4351794d80db3c917b374648a2090c89619b9bd9deb556955a86eb230118814930d2b8d363838b49f0d2a75d7cee0f8f91bbc2393146cc8cecc9c4f68
checksums.yaml.gz.sig CHANGED
Binary file
@@ -10,54 +10,46 @@ module Protocol
10
10
  module Header
11
11
  # Represents the `priority` header, used to indicate the relative importance of an HTTP request.
12
12
  #
13
- # The `priority` header allows clients to express their preference for how resources should be prioritized by the server. It can include directives like `urgency` to specify the importance of a request, and `progressive` to indicate whether a response can be delivered incrementally.
13
+ # The `priority` header allows clients to express their preference for how resources should be prioritized by the server. It supports directives like `u=` to specify the urgency level of a request, and `i` to indicate whether a response can be delivered incrementally. The urgency levels range from 0 (highest priority) to 7 (lowest priority), while the `i` directive is a boolean flag.
14
14
  class Priority < Split
15
- # Urgency levels as defined in RFC 9218:
16
- #
17
- # These levels indicate the relative importance of a request, helping servers and intermediaries allocate resources efficiently. Properly setting urgency can significantly improve user-perceived performance by prioritizing critical content and deferring less important tasks.
18
- module Urgency
19
- # `background` priority indicates a request that is not time-sensitive and can be processed with minimal impact to other tasks. It is ideal for requests like analytics or logging, which do not directly impact the user's current experience.
20
- BACKGROUND = "background"
21
-
22
- # `low` priority indicates a request that is important but not critical. It is suitable for content like non-blocking images, videos, or scripts that enhance the experience but do not affect core functionality.
23
- LOW = "low"
24
-
25
- # `normal` priority (default) indicates the standard priority for most requests. It is appropriate for content like text, CSS, or essential images that are necessary for the primary user experience but do not require urgent delivery.
26
- NORMAL = "normal"
27
-
28
- # `high` priority indicates the highest priority, used for requests that are essential and time-critical to the user experience. Examples include content above-the-fold on a webpage, critical API calls, or resources required for rendering.
29
- HIGH = "high"
30
- end
31
-
32
- # The `progressive` flag indicates that the response can be delivered incrementally (progressively) as data becomes available. This is particularly useful for large resources like images or video streams, where partial delivery improves the user experience by allowing content to render or play before the full response is received.
33
- PROGRESSIVE = "progressive"
34
-
35
15
  # Initialize the priority header with the given value.
36
16
  #
37
- # @parameter value [String | Nil] the value of the priority header, if any.
17
+ # @parameter value [String | Nil] the value of the priority header, if any. The value should be a comma-separated string of directives.
38
18
  def initialize(value = nil)
39
19
  super(value&.downcase)
40
20
  end
41
21
 
42
22
  # Add a value to the priority header.
23
+ #
24
+ # @parameter value [String] the directive to add to the header.
43
25
  def << value
44
26
  super(value.downcase)
45
27
  end
46
28
 
47
- # Returns the urgency level if specified.
29
+ # The default urgency level if not specified.
30
+ DEFAULT_URGENCY = 3
31
+
32
+ # The urgency level, if specified using `u=`. 0 is the highest priority, and 7 is the lowest.
33
+ #
34
+ # Note that when duplicate Dictionary keys are encountered, all but the last instance are ignored.
48
35
  #
49
- # @returns [String | Nil] the urgency level if specified, or `nil`.
50
- def urgency
51
- if value = self.find{|value| value.start_with?("urgency=")}
36
+ # @returns [Integer | Nil] the urgency level if specified, or `nil` if not present.
37
+ def urgency(default = DEFAULT_URGENCY)
38
+ if value = self.reverse_find{|value| value.start_with?("u=")}
52
39
  _, level = value.split("=", 2)
53
-
54
- return level
40
+ return Integer(level)
55
41
  end
42
+
43
+ return default
56
44
  end
57
45
 
58
- # @returns [Boolean] whether the request should be delivered progressively.
59
- def progressive?
60
- self.include?(PROGRESSIVE)
46
+ # Checks if the response should be delivered incrementally.
47
+ #
48
+ # The `i` directive, when present, indicates that the response can be delivered incrementally as data becomes available.
49
+ #
50
+ # @returns [Boolean] whether the request should be delivered incrementally.
51
+ def incremental?
52
+ self.include?("i")
61
53
  end
62
54
  end
63
55
  end
@@ -39,6 +39,16 @@ module Protocol
39
39
  def to_s
40
40
  join(",")
41
41
  end
42
+
43
+ protected
44
+
45
+ def reverse_find(&block)
46
+ reverse_each do |value|
47
+ return value if block.call(value)
48
+ end
49
+
50
+ return nil
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.46.0"
8
+ VERSION = "0.47.1"
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-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.46.0
4
+ version: 0.47.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -47,7 +47,7 @@ cert_chain:
47
47
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
48
48
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
49
49
  -----END CERTIFICATE-----
50
- date: 2024-11-28 00:00:00.000000000 Z
50
+ date: 2024-12-04 00:00:00.000000000 Z
51
51
  dependencies: []
52
52
  description:
53
53
  email:
metadata.gz.sig CHANGED
Binary file