class TransferEncoding
The transfer-encoding header indicates the encoding transformations that have been applied to the message body.
The transfer-encoding header is used to specify the form of encoding used to safely transfer the message body between the sender and receiver.
Definitions
CHUNKED = "chunked"
The chunked transfer encoding allows a server to send data of unknown length by breaking it into chunks.
GZIP = "gzip"
The gzip transfer encoding compresses the message body using the gzip algorithm.
DEFLATE = "deflate"
The deflate transfer encoding compresses the message body using the deflate algorithm.
COMPRESS = "compress"
The compress transfer encoding compresses the message body using the compress algorithm.
IDENTITY = "identity"
The identity transfer encoding indicates no transformation has been applied.
def self.parse(value)
Parses a raw header value.
Signature
-
parameter
valueString a raw header value containing comma-separated encodings.
-
returns
TransferEncoding a new instance with normalized (lowercase) encodings.
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
valueString | Array the value to coerce.
-
returns
TransferEncoding 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)
Adds one or more comma-separated values to the transfer encoding header. The values are converted to lowercase for normalization.
Signature
-
parameter
valueString a raw header value containing one or more values separated by commas.
Implementation
def << value
super(value.downcase)
end
def chunked?
Signature
-
returns
Boolean whether the
chunkedencoding is present.
Implementation
def chunked?
self.include?(CHUNKED)
end
def gzip?
Signature
-
returns
Boolean whether the
gzipencoding is present.
Implementation
def gzip?
self.include?(GZIP)
end
def deflate?
Signature
-
returns
Boolean whether the
deflateencoding is present.
Implementation
def deflate?
self.include?(DEFLATE)
end
def compress?
Signature
-
returns
Boolean whether the
compressencoding is present.
Implementation
def compress?
self.include?(COMPRESS)
end
def identity?
Signature
-
returns
Boolean whether the
identityencoding is present.
Implementation
def identity?
self.include?(IDENTITY)
end
def self.trailer?
Whether this header is acceptable in HTTP trailers. Transfer-Encoding headers control message framing and must not appear in trailers.
Signature
-
returns
Boolean false, as Transfer-Encoding headers are hop-by-hop and must precede the message body.
Implementation
def self.trailer?
false
end