Class: Protocol::HTTP::Header::Priority

Inherits:
Split
  • Object
show all
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

Split::COMMA

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Split

#initialize, #to_s, trailer?

Constructor Details

This class inherits a constructor from Protocol::HTTP::Header::Split

Class Method Details

.coerce(value) ⇒ Object

Coerces a value into a parsed header object.



27
28
29
30
31
32
33
34
# File 'lib/protocol/http/header/priority.rb', line 27

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

.parse(value) ⇒ Object

Parses a raw header value.



19
20
21
# File 'lib/protocol/http/header/priority.rb', line 19

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

Instance Method Details

#<<(value) ⇒ Object

Add a value to the priority header.



39
40
41
# File 'lib/protocol/http/header/priority.rb', line 39

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.

Returns:

  • (Boolean)


65
66
67
# File 'lib/protocol/http/header/priority.rb', line 65

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.



51
52
53
54
55
56
57
58
# File 'lib/protocol/http/header/priority.rb', line 51

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