Protocol::HTTPSourceProtocolHTTPHeaderPriority

class Priority

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.

Definitions

def self.parse(value)

Parses a raw header value.

Signature

parameter value String

a raw header value containing comma-separated directives.

returns Priority

a new instance with normalized (lowercase) directives.

Implementation

def self.parse(value)
	self.new(value.downcase.split(COMMA))
end

def self.coerce(value)

Coerces a value into a parsed header object.

Signature

parameter value String | Array

the value to coerce.

returns Priority

a parsed header object with normalized values.

Implementation

def self.coerce(value)
	case value
	when Array
		self.new(value.map(&:downcase))
	else
		self.parse(value.to_s)
	end
end

def <<(value)

Add a value to the priority header.

Signature

parameter value String

a raw header value containing directives to add to the header.

Implementation

def << value
	super(value.downcase)
end

DEFAULT_URGENCY = 3

The default urgency level if not specified.

def urgency(default = DEFAULT_URGENCY)

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.

Signature

returns Integer | Nil

the urgency level if specified, or nil if not present.

Implementation

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

def incremental?

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.

Signature

returns Boolean

whether the request should be delivered incrementally.

Implementation

def incremental?
	self.include?("i")
end