mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[ruby/net-http] Enhanced RDoc for header Range
(https://github.com/ruby/net-http/pull/82)
a26f62a2e5
This commit is contained in:
parent
579c8cb01c
commit
ee49fe5d34
1 changed files with 33 additions and 9 deletions
|
@ -145,7 +145,7 @@
|
||||||
# - #content_length=: Sets the integer length for field <tt>'Content-Length</tt>.
|
# - #content_length=: Sets the integer length for field <tt>'Content-Length</tt>.
|
||||||
# - #content_type=: Sets the string value for field <tt>'Content-Type'</tt>.
|
# - #content_type=: Sets the string value for field <tt>'Content-Type'</tt>.
|
||||||
# - #proxy_basic_auth: Sets the string authorization header for <tt>'Proxy-Authorization'</tt>.
|
# - #proxy_basic_auth: Sets the string authorization header for <tt>'Proxy-Authorization'</tt>.
|
||||||
# - #range=: Sets the value for field +'Range'+.
|
# - #set_range: Sets the value for field <tt>'Range'</tt>.
|
||||||
#
|
#
|
||||||
# === Queries
|
# === Queries
|
||||||
#
|
#
|
||||||
|
@ -460,8 +460,16 @@ module Net::HTTPHeader
|
||||||
end
|
end
|
||||||
private :capitalize
|
private :capitalize
|
||||||
|
|
||||||
# Returns an Array of Range objects which represent the Range:
|
# Returns an array of Range objects that represent
|
||||||
# HTTP header field, or +nil+ if there is no such header.
|
# the value of field <tt>'Range'</tt>,
|
||||||
|
# or +nil+ if there is no such field;
|
||||||
|
# see {Range request header}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#range-request-header]:
|
||||||
|
#
|
||||||
|
# req['Range'] = 'bytes=0-99,200-299,400-499'
|
||||||
|
# req.range # => [0..99, 200..299, 400..499]
|
||||||
|
# req.delete('Range')
|
||||||
|
# req.range # # => nil
|
||||||
|
#
|
||||||
def range
|
def range
|
||||||
return nil unless @header['range']
|
return nil unless @header['range']
|
||||||
|
|
||||||
|
@ -504,14 +512,30 @@ module Net::HTTPHeader
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the HTTP Range: header.
|
# :call-seq:
|
||||||
# Accepts either a Range object as a single argument,
|
# set_range(length) -> length
|
||||||
# or a beginning index and a length from that index.
|
# set_range(offset, length) -> range
|
||||||
# Example:
|
# set_range(begin..length) -> range
|
||||||
#
|
#
|
||||||
# req.range = (0..1023)
|
# Sets the value for field <tt>'Range'</tt>;
|
||||||
# req.set_range 0, 1023
|
# see {Range request header}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#range-request-header]:
|
||||||
#
|
#
|
||||||
|
# With argument +length+:
|
||||||
|
#
|
||||||
|
# req.set_range(100) # => 100
|
||||||
|
# req['Range'] # => "bytes=0-99"
|
||||||
|
#
|
||||||
|
# With arguments +offset+ and +length+:
|
||||||
|
#
|
||||||
|
# req.set_range(100, 100) # => 100...200
|
||||||
|
# req['Range'] # => "bytes=100-199"
|
||||||
|
#
|
||||||
|
# With argument +range+:
|
||||||
|
#
|
||||||
|
# req.set_range(100..199) # => 100..199
|
||||||
|
# req['Range'] # => "bytes=100-199"
|
||||||
|
#
|
||||||
|
# Net::HTTPHeader#range= is an alias for Net::HTTPHeader#set_range.
|
||||||
def set_range(r, e = nil)
|
def set_range(r, e = nil)
|
||||||
unless r
|
unless r
|
||||||
@header.delete 'range'
|
@header.delete 'range'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue