Returns the IP address for the connection.
If the session has not been started, returns the value set by ipaddr=
, or nil
if it has not been set:
http = Net::HTTP.new(hostname) http.ipaddr # => nil http.ipaddr = '172.67.155.76' http.ipaddr # => "172.67.155.76"
If the session has been started, returns the IP address from the socket:
http = Net::HTTP.new(hostname) http.start http.ipaddr # => "172.67.155.76" http.finish
Sets the IP address for the connection:
http = Net::HTTP.new(hostname) http.ipaddr # => nil http.ipaddr = '172.67.155.76' http.ipaddr # => "172.67.155.76"
The IP address may not be set if the session has been started.
Returns true
if the HTTP session has been started:
http = Net::HTTP.new(hostname) http.started? # => false http.start http.started? # => true http.finish # => nil http.started? # => false Net::HTTP.start(hostname) do |http| http.started? end # => true http.started? # => false
Starts an HTTP session.
Without a block, returns self
:
http = Net::HTTP.new(hostname) # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false> http.start # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=true> http.started? # => true http.finish
With a block, calls the block with self
, finishes the session when the block exits, and returns the block’s value:
http.start do |http| http end # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false> http.started? # => false
Sends a POST request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With a block given, calls the block with the response body:
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.post('/todos', data) do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\",\n \"id\": 201\n}"
With no block given, simply returns the response object:
http.post('/todos', data) # => #<Net::HTTPCreated 201 Created readbody=true>
Related:
Net::HTTP::Post
: request class for HTTP method POST.
Net::HTTP.post
: sends POST request, returns response body.
Sends a TRACE request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Trace
object created from string path
and initial headers hash initheader
.
http = Net::HTTP.new(hostname) http.trace('/todos/1')
Sends the given request req
to the server; forms the response into a Net::HTTPResponse
object.
The given req
must be an instance of a subclass of Net::HTTPRequest. Argument body
should be given only if needed for the request.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) req = Net::HTTP::Get.new('/todos/1') http.request(req) # => #<Net::HTTPOK 200 OK readbody=true> req = Net::HTTP::Post.new('/todos') http.request(req, 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response and returns the response:
req = Net::HTTP::Get.new('/todos/1') http.request(req) do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
#<Net::HTTPOK 200 OK readbody=false>
Returns the authority for an HTTP
uri, as defined in datatracker.ietf.org/doc/html/rfc3986/#section-3.2.
Example:
URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').authority #=> "www.example.com" URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').authority #=> "www.example.com:8000" URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').authority #=> "www.example.com"
Returns the origin for an HTTP
uri, as defined in datatracker.ietf.org/doc/html/rfc6454.
Example:
URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').origin #=> "http://www.example.com" URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').origin #=> "http://www.example.com:8000" URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').origin #=> "http://www.example.com" URI::HTTPS.build(host: 'www.example.com', path: '/foo/bar').origin #=> "https://www.example.com"
Produces the summary text. Each line of the summary is yielded to the block (without newline).
sdone
Already summarized short style options keyed hash.
ldone
Already summarized long style options keyed hash.
width
Width of left side (option part). In other words, the right side (description part) starts after width
columns.
max
Maximum width of left side -> the options are filled within max
columns.
indent
Prefix string indents all summarized lines.
Creates the summary table, passing each line to the block
(without newline). The arguments args
are passed along to the summarize method which is called on every option.
This is used as a predicate, and ought to be called first.
Register a listener for one or more events.
def register: (Listener, *Symbol) -> void
Returns true if this comment happens on the same line as other code and false if the comment is by itself.
This can only be true for inline comments.
Look up the typeclass
DNS
resource of name
.
name
must be a Resolv::DNS::Name
or a String
.
typeclass
should be one of the following:
Resolv::DNS::Resource::IN::ANY
Resolv::DNS::Resource::IN::CNAME
Resolv::DNS::Resource::IN::HINFO
Resolv::DNS::Resource::IN::MINFO
Resolv::DNS::Resource::IN::MX
Resolv::DNS::Resource::IN::NS
Resolv::DNS::Resource::IN::PTR
Resolv::DNS::Resource::IN::SOA
Resolv::DNS::Resource::IN::TXT
Returned resource is represented as a Resolv::DNS::Resource
instance, i.e. Resolv::DNS::Resource::IN::A
.
Looks up all typeclass
DNS
resources for name
. See getresource
for argument details.
Adds tuple
to the proxied TupleSpace
. See TupleSpace#write
.
Returns the first advertised TupleSpace
.
Adds tuple