Class: Protocol::HTTP::Header::Priority
- Defined in:
- lib/protocol/http/header/priority.rb
Overview
Represents the ‘priority` header, used to indicate the relative importance of an HTTP request.
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.
Constant Summary collapse
- DEFAULT_URGENCY =
The default urgency level if not specified.
3
Constants inherited from Split
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Add a value to the priority header.
-
#incremental? ⇒ Boolean
Checks if the response should be delivered incrementally.
-
#initialize(value = nil) ⇒ Priority
constructor
Initialize the priority header with the given value.
-
#urgency(default = DEFAULT_URGENCY) ⇒ Object
The urgency level, if specified using ‘u=`.
Methods inherited from Split
Constructor Details
#initialize(value = nil) ⇒ Priority
Initialize the priority header with the given value.
18 19 20 |
# File 'lib/protocol/http/header/priority.rb', line 18 def initialize(value = nil) super(value&.downcase) end |
Instance Method Details
#<<(value) ⇒ Object
Add a value to the priority header.
25 26 27 |
# File 'lib/protocol/http/header/priority.rb', line 25 def << value super(value.downcase) end |
#incremental? ⇒ Boolean
Checks if the response should be delivered incrementally.
The ‘i` directive, when present, indicates that the response can be delivered incrementally as data becomes available.
51 52 53 |
# File 'lib/protocol/http/header/priority.rb', line 51 def incremental? self.include?("i") end |
#urgency(default = DEFAULT_URGENCY) ⇒ Object
The urgency level, if specified using ‘u=`. 0 is the highest priority, and 7 is the lowest.
Note that when duplicate Dictionary keys are encountered, all but the last instance are ignored.
37 38 39 40 41 42 43 44 |
# File 'lib/protocol/http/header/priority.rb', line 37 def urgency(default = DEFAULT_URGENCY) if value = self.reverse_find{|value| value.start_with?("u=")} _, level = value.split("=", 2) return Integer(level) end return default end |