Skip to content

Commit a26f62a

Browse files
Enhanced RDoc for header Range (#82)
1 parent 77c6878 commit a26f62a

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

lib/net/http/header.rb

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
# - #content_length=: Sets the integer length for field <tt>'Content-Length</tt>.
146146
# - #content_type=: Sets the string value for field <tt>'Content-Type'</tt>.
147147
# - #proxy_basic_auth: Sets the string authorization header for <tt>'Proxy-Authorization'</tt>.
148-
# - #range=: Sets the value for field +'Range'+.
148+
# - #set_range: Sets the value for field <tt>'Range'</tt>.
149149
#
150150
# === Queries
151151
#
@@ -460,8 +460,16 @@ def capitalize(name)
460460
end
461461
private :capitalize
462462

463-
# Returns an Array of Range objects which represent the Range:
464-
# HTTP header field, or +nil+ if there is no such header.
463+
# Returns an array of Range objects that represent
464+
# the value of field <tt>'Range'</tt>,
465+
# or +nil+ if there is no such field;
466+
# see {Range request header}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#range-request-header]:
467+
#
468+
# req['Range'] = 'bytes=0-99,200-299,400-499'
469+
# req.range # => [0..99, 200..299, 400..499]
470+
# req.delete('Range')
471+
# req.range # # => nil
472+
#
465473
def range
466474
return nil unless @header['range']
467475

@@ -504,14 +512,30 @@ def range
504512
result
505513
end
506514

507-
# Sets the HTTP Range: header.
508-
# Accepts either a Range object as a single argument,
509-
# or a beginning index and a length from that index.
510-
# Example:
515+
# :call-seq:
516+
# set_range(length) -> length
517+
# set_range(offset, length) -> range
518+
# set_range(begin..length) -> range
519+
#
520+
# Sets the value for field <tt>'Range'</tt>;
521+
# see {Range request header}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#range-request-header]:
522+
#
523+
# With argument +length+:
524+
#
525+
# req.set_range(100) # => 100
526+
# req['Range'] # => "bytes=0-99"
527+
#
528+
# With arguments +offset+ and +length+:
529+
#
530+
# req.set_range(100, 100) # => 100...200
531+
# req['Range'] # => "bytes=100-199"
532+
#
533+
# With argument +range+:
511534
#
512-
# req.range = (0..1023)
513-
# req.set_range 0, 1023
535+
# req.set_range(100..199) # => 100..199
536+
# req['Range'] # => "bytes=100-199"
514537
#
538+
# Net::HTTPHeader#range= is an alias for Net::HTTPHeader#set_range.
515539
def set_range(r, e = nil)
516540
unless r
517541
@header.delete 'range'

0 commit comments

Comments
 (0)