method
range
v2_1_10 -
Show latest stable
- Class:
Net::HTTPHeader
range()public
Returns an Array of Range objects which represent the Range: HTTP header field, or nil if there is no such header.
# File lib/net/http/header.rb, line 178
def range
return nil unless @header['range']
value = self['Range']
# byte-range-set = *( "," OWS ) ( byte-range-spec / suffix-byte-range-spec )
# *( OWS "," [ OWS ( byte-range-spec / suffix-byte-range-spec ) ] )
# corrected collected ABNF
# http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-19#section-5.4.1
# http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-19#appendix-C
# http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-19#section-3.2.5
unless /\Abytes=((?:,[ \t]*)*(?:\d+-\d*|-\d+)(?:[ \t]*,(?:[ \t]*\d+-\d*|-\d+)?)*)\z/ =~ value
raise Net::HTTPHeaderSyntaxError, "invalid syntax for byte-ranges-specifier: '#{value}'"
end
byte_range_set = $1
result = byte_range_set.split(/,/).map {|spec|
m = /(\d+)?\s*-\s*(\d+)?/.match(spec) or
raise Net::HTTPHeaderSyntaxError, "invalid byte-range-spec: '#{spec}'"
d1 = m[1].to_i
d2 = m[2].to_i
if m[1] and m[2]
if d1 > d2
raise Net::HTTPHeaderSyntaxError, "last-byte-pos MUST greater than or equal to first-byte-pos but '#{spec}'"
end
d1..d2
elsif m[1]
d1..-1
elsif m[2]
-d2..-1
else
raise Net::HTTPHeaderSyntaxError, 'range is not specified'
end
}
# if result.empty?
# byte-range-set must include at least one byte-range-spec or suffix-byte-range-spec
# but above regexp already denies it.
if result.size == 1 && result[0].begin == 0 && result[0].end == -1
raise Net::HTTPHeaderSyntaxError, 'only one suffix-byte-range-spec with zero suffix-length'
end
result
end Related methods
- Instance methods
- []
- []=
- add_field
- basic_auth
- canonical_each
- chunked?
- connection_close?
- connection_keep_alive?
- content_length
- content_length=
- content_range
- content_type
- content_type=
- delete
- each
- each_capitalized
- each_capitalized_name
- each_header
- each_key
- each_name
- each_value
- fetch
- form_data=
- get_fields
- initialize_http_header
- key?
- length
- main_type
- proxy_basic_auth
- range
- range=
- range_length
- set_content_type
- set_form
- set_form_data
- set_range
- size
- sub_type
- to_hash
- type_params
- Private methods
-
basic_encode -
capitalize -
tokens