Class: Protocol::HTTP::Header::TE
- Defined in:
- lib/protocol/http/header/te.rb
Overview
The ‘te` header indicates the transfer encodings the client is willing to accept. AKA `accept-transfer-encoding`. How we ended up with `te` instead of `accept-transfer-encoding` is a mystery lost to time.
The ‘te` header allows a client to indicate which transfer encodings it can handle, and in what order of preference using quality factors.
Defined Under Namespace
Classes: TransferCoding
Constant Summary collapse
- ParseError =
Class.new(Error)
- TOKEN =
Transfer encoding token pattern
/[!#$%&'*+\-.0-9A-Z^_`a-z|~]+/- QVALUE =
Quality value pattern (0.0 to 1.0)
/0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/- TRANSFER_CODING =
Pattern for parsing transfer encoding with optional quality factor
/\A(?<name>#{TOKEN})(\s*;\s*q=(?<q>#{QVALUE}))?\z/- CHUNKED =
The ‘chunked` transfer encoding
"chunked"- GZIP =
The ‘gzip` transfer encoding
"gzip"- DEFLATE =
The ‘deflate` transfer encoding
"deflate"- COMPRESS =
The ‘compress` transfer encoding
"compress"- IDENTITY =
The ‘identity` transfer encoding
"identity"- TRAILERS =
The ‘trailers` pseudo-encoding indicates willingness to accept trailer fields
"trailers"
Constants inherited from Split
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
-
.parse(value) ⇒ Object
Parses a raw header value.
-
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds one or more comma-separated values to the TE header.
- #chunked? ⇒ Boolean
- #compress? ⇒ Boolean
- #deflate? ⇒ Boolean
- #gzip? ⇒ Boolean
- #identity? ⇒ Boolean
- #trailers? ⇒ Boolean
-
#transfer_codings ⇒ Object
Parse the ‘te` header value into a list of transfer codings with quality factors.
Methods inherited from Split
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.
77 78 79 80 81 82 83 84 |
# File 'lib/protocol/http/header/te.rb', line 77 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.
69 70 71 |
# File 'lib/protocol/http/header/te.rb', line 69 def self.parse(value) self.new(value.downcase.split(COMMA)) end |
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers. TE headers negotiate transfer encodings and must not appear in trailers.
139 140 141 |
# File 'lib/protocol/http/header/te.rb', line 139 def self.trailer? false end |
Instance Method Details
#<<(value) ⇒ Object
Adds one or more comma-separated values to the TE header. The values are converted to lowercase for normalization.
89 90 91 |
# File 'lib/protocol/http/header/te.rb', line 89 def << value super(value.downcase) end |
#chunked? ⇒ Boolean
107 108 109 |
# File 'lib/protocol/http/header/te.rb', line 107 def chunked? self.any? {|value| value.start_with?(CHUNKED)} end |
#compress? ⇒ Boolean
122 123 124 |
# File 'lib/protocol/http/header/te.rb', line 122 def compress? self.any? {|value| value.start_with?(COMPRESS)} end |
#deflate? ⇒ Boolean
117 118 119 |
# File 'lib/protocol/http/header/te.rb', line 117 def deflate? self.any? {|value| value.start_with?(DEFLATE)} end |
#gzip? ⇒ Boolean
112 113 114 |
# File 'lib/protocol/http/header/te.rb', line 112 def gzip? self.any? {|value| value.start_with?(GZIP)} end |
#identity? ⇒ Boolean
127 128 129 |
# File 'lib/protocol/http/header/te.rb', line 127 def identity? self.any? {|value| value.start_with?(IDENTITY)} end |
#trailers? ⇒ Boolean
132 133 134 |
# File 'lib/protocol/http/header/te.rb', line 132 def trailers? self.any? {|value| value.start_with?(TRAILERS)} end |
#transfer_codings ⇒ Object
Parse the ‘te` header value into a list of transfer codings with quality factors.
96 97 98 99 100 101 102 103 104 |
# File 'lib/protocol/http/header/te.rb', line 96 def transfer_codings self.map do |value| if match = value.match(TRANSFER_CODING) TransferCoding.new(match[:name], match[:q]) else raise ParseError.new("Could not parse transfer coding: #{value.inspect}") end end end |