Calculates relative path to oth from self.
require 'uri' uri = URI.parse('http://my.example.com') uri.route_to('http://my.example.com/main.rbx?page=1') #=> #<URI::Generic /main.rbx?page=1>
Checks the to v
component.
Private setter for to v
.
Returns the RFC822 e-mail text equivalent of the URL, as a String
.
Example:
require 'uri' uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr") uri.to_mailtext # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
Returns Regexp
that is default self.regexp[:ABS_URI_REF]
, unless schemes
is provided. Then it is a Regexp.union
with self.pattern[:X_ABS_URI]
.
Constructs the default Hash
of Regexp’s.
Converts the contents of the database to an in-memory Hash
object, and returns it.
Invoked by IO#read
or IO#Buffer.read to read length
bytes from io
into a specified buffer
(see IO::Buffer
) at the given offset
.
The length
argument is the “minimum length to be read”. If the IO
buffer size is 8KiB, but the length
is 1024
(1KiB), up to 8KiB might be read, but at least 1KiB will be. Generally, the only case where less data than length
will be read is if there is an error reading the data.
Specifying a length
of 0 is valid and means try reading at least once and return any available data.
Suggested implementation should try to read from io
in a non-blocking manner and call io_wait
if the io
is not ready (which will yield control to other fibers).
See IO::Buffer
for an interface available to return data.
Expected to return number of bytes read, or, in case of an error, -errno
(negated number corresponding to system’s error code).
The method should be considered experimental.
Returns the destination encoding as an encoding object.
Returns the one-character string which cause Encoding::UndefinedConversionError
.
ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP") begin ec.convert("\xa0") rescue Encoding::UndefinedConversionError puts $!.error_char.dump #=> "\xC2\xA0" p $!.error_char.encoding #=> #<Encoding:UTF-8> end
Returns the destination encoding as an encoding object.
Returns the discarded bytes when Encoding::InvalidByteSequenceError
occurs.
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") begin ec.convert("abc\xA1\xFFdef") rescue Encoding::InvalidByteSequenceError p $! #=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "\xFF" on EUC-JP> puts $!.error_bytes.dump #=> "\xA1" puts $!.readagain_bytes.dump #=> "\xFF" end
Returns the bytes to be read again when Encoding::InvalidByteSequenceError
occurs.
Returns the destination encoding as an Encoding
object.
Returns the length of the hash value of the digest.
This method should be overridden by each implementation subclass. If not, digest_obj.digest().length() is returned.
Reads at most maxlen bytes in the non-blocking manner.
When no data can be read without blocking it raises OpenSSL::SSL::SSLError
extended by IO::WaitReadable
or IO::WaitWritable
.
IO::WaitReadable
means SSL
needs to read internally so read_nonblock
should be called again when the underlying IO
is readable.
IO::WaitWritable
means SSL
needs to write internally so read_nonblock
should be called again after the underlying IO
is writable.
OpenSSL::Buffering#read_nonblock
needs two rescue clause as follows:
# emulates blocking read (readpartial). begin result = ssl.read_nonblock(maxlen) rescue IO::WaitReadable IO.select([io]) retry rescue IO::WaitWritable IO.select(nil, [io]) retry end
Note that one reason that read_nonblock
writes to the underlying IO
is when the peer requests a new TLS/SSL handshake. See openssl the FAQ for more details. www.openssl.org/support/faq.html
By specifying a keyword argument exception to false
, you can indicate that read_nonblock
should not raise an IO::Wait*able exception, but return the symbol :wait_writable
or :wait_readable
instead. At EOF, it will return nil
instead of raising EOFError
.
just for compatibility
Returns a hash of the key/value pairs:
req = Net::HTTP::Get.new(uri) req.to_hash # => {"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "accept"=>["*/*"], "user-agent"=>["Ruby"], "host"=>["jsonplaceholder.typicode.com"]}
Stores form data to be used in a POST
or PUT
request.
The form data given in params
consists of zero or more fields; each field is:
A scalar value.
A name/value pair.
An IO
stream opened for reading.
Argument params
should be an Enumerable (method params.map
will be called), and is often an array or hash.
First, we set up a request:
_uri = uri.dup _uri.path ='/posts' req = Net::HTTP::Post.new(_uri)
Argument params
As an Array
When params
is an array, each of its elements is a subarray that defines a field; the subarray may contain:
One string:
req.set_form([['foo'], ['bar'], ['baz']])
Two strings:
req.set_form([%w[foo 0], %w[bar 1], %w[baz 2]])
When argument enctype
(see below) is given as 'multipart/form-data'
:
A string name and an IO
stream opened for reading:
require 'stringio' req.set_form([['file', StringIO.new('Ruby is cool.')]])
A string name, an IO
stream opened for reading, and an options hash, which may contain these entries:
:filename
: The name of the file to use.
:content_type
: The content type of the uploaded file.
Example:
req.set_form([['file', file, {filename: "other-filename.foo"}]]
The various forms may be mixed:
req.set_form(['foo', %w[bar 1], ['file', file]])
Argument params
As a Hash
When params
is a hash, each of its entries is a name/value pair that defines a field:
The name is a string.
The value may be:
nil
.
Another string.
An IO
stream opened for reading (only when argument enctype
– see below – is given as 'multipart/form-data'
).
Examples:
# Nil-valued fields. req.set_form({'foo' => nil, 'bar' => nil, 'baz' => nil}) # String-valued fields. req.set_form({'foo' => 0, 'bar' => 1, 'baz' => 2}) # IO-valued field. require 'stringio' req.set_form({'file' => StringIO.new('Ruby is cool.')}) # Mixture of fields. req.set_form({'foo' => nil, 'bar' => 1, 'file' => file})
Optional argument enctype
specifies the value to be given to field 'Content-Type'
, and must be one of:
'application/x-www-form-urlencoded'
(the default).
'multipart/form-data'
; see RFC 7578.
Optional argument formopt
is a hash of options (applicable only when argument enctype
is 'multipart/form-data'
) that may include the following entries:
:boundary
: The value is the boundary string for the multipart message. If not given, the boundary is a random string. See Boundary.
:charset
: Value is the character set for the form submission. Field names and values of non-file fields should be encoded with this charset.