Class: Quicsilver::Protocol::Priority
- Inherits:
-
Object
- Object
- Quicsilver::Protocol::Priority
- Defined in:
- lib/quicsilver/protocol/priority.rb
Overview
HTTP Extensible Priorities (RFC 9218).
Parses the ‘priority` header from HTTP requests. Urgency ranges from 0 (highest) to 7 (lowest), defaulting to 3. Incremental indicates whether partial data is useful to the client (e.g. progressive images).
Usage:
priority = Priority.parse("u=0, i")
priority.urgency # => 0
priority.incremental # => true
priority = Priority.parse(nil) # default
priority.urgency # => 3
priority.incremental # => false
Constant Summary collapse
- DEFAULT_URGENCY =
3- MIN_URGENCY =
0- MAX_URGENCY =
7
Instance Attribute Summary collapse
-
#incremental ⇒ Object
readonly
Returns the value of attribute incremental.
-
#urgency ⇒ Object
readonly
Returns the value of attribute urgency.
Class Method Summary collapse
-
.parse(value) ⇒ Object
Parse a priority header value (RFC 9218 §4, Structured Field Values).
Instance Method Summary collapse
-
#initialize(urgency: DEFAULT_URGENCY, incremental: false) ⇒ Priority
constructor
A new instance of Priority.
Constructor Details
#initialize(urgency: DEFAULT_URGENCY, incremental: false) ⇒ Priority
Returns a new instance of Priority.
26 27 28 29 |
# File 'lib/quicsilver/protocol/priority.rb', line 26 def initialize(urgency: DEFAULT_URGENCY, incremental: false) @urgency = urgency.clamp(MIN_URGENCY, MAX_URGENCY) @incremental = incremental end |
Instance Attribute Details
#incremental ⇒ Object (readonly)
Returns the value of attribute incremental.
24 25 26 |
# File 'lib/quicsilver/protocol/priority.rb', line 24 def incremental @incremental end |
#urgency ⇒ Object (readonly)
Returns the value of attribute urgency.
24 25 26 |
# File 'lib/quicsilver/protocol/priority.rb', line 24 def urgency @urgency end |
Class Method Details
.parse(value) ⇒ Object
Parse a priority header value (RFC 9218 §4, Structured Field Values). Returns a Priority with defaults for missing or invalid values.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/quicsilver/protocol/priority.rb', line 33 def self.parse(value) return new unless value && !value.empty? urgency = DEFAULT_URGENCY incremental = false value.split(",").each do |param| param = param.strip if param.start_with?("u=") urgency = param[2..].to_i elsif param == "i" incremental = true elsif param == "i=?0" incremental = false elsif param == "i=?1" incremental = true end end new(urgency: urgency, incremental: incremental) end |