code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def resolver_returning_error
resolver = Dnsruby::Resolver.new
def resolver.send_plain_message(_message)
[nil, CustomError.new]
end
resolver
end
|
Returns a new resolver whose send_plain_message method always returns
nil for the response, and a RuntimeError for the error.
|
resolver_returning_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def resolver_returning_response
resolver = Dnsruby::Resolver.new
def resolver.send_plain_message(_message)
[:response_from_send_plain_message, nil]
end
resolver
end
|
Returns a new resolver whose send_plain_message is overridden to return
:response_from_send_plain_message instead of a real Dnsruby::Message,
for easy comparison in the tests.
|
resolver_returning_response
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_bad_strategy
assert_raises(ArgumentError) do
resolver_returning_error.query_raw(Dnsruby::Message.new, :invalid_strategy)
end
end
|
Test that when a strategy other than :raise or :return is passed,
an ArgumentError is raised.
|
test_bad_strategy
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_raise_error
assert_raises(CustomError) do
resolver_returning_error.query_raw(Dnsruby::Message.new, :raise)
end
end
|
Test that when send_plain_message returns an error,
and the error strategy is :raise, query_raw raises an error.
|
test_raise_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_return_error_is_default
_response, error = resolver_returning_error.query_raw(Dnsruby::Message.new)
assert error.is_a?(CustomError)
end
|
Tests that if you don't specify an error strategy, an error will be
returned rather than raised (i.e. strategy defaults to :return).
|
test_return_error_is_default
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_raise_no_error
response, _error = resolver_returning_response.query_raw(Dnsruby::Message.new, :raise)
assert_equal :response_from_send_plain_message, response
end
|
Tests that when no error is returned, no error is raised.
|
test_raise_no_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_return_error
_response, error = resolver_returning_error.query_raw(Dnsruby::Message.new, :return)
assert error.is_a?(CustomError)
end
|
Test that when send_plain_message returns an error, and the error strategy
is set to :return, then an error is returned.
|
test_return_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_return_no_error
response, error = resolver_returning_response.query_raw(Dnsruby::Message.new, :return)
assert_nil error
assert_equal :response_from_send_plain_message, response
end
|
Test that when send_plain_message returns a valid and response
and nil error, the same are returned by query_raw.
|
test_return_no_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_resolver.rb
|
Apache-2.0
|
def test_res_env
ENV['RES_NAMESERVERS'] = '10.0.1.128 10.0.2.128';
ENV['RES_SEARCHLIST'] = 'dnsruby.validation-test-servers.nominet.org.uk lib.dnsruby.validation-test-servers.nominet.org.uk';
ENV['LOCALDOMAIN'] = 't.dnsruby.validation-test-servers.nominet.org.uk';
ENV['RES_OPTIONS'] = 'retrans:3 retry:2 debug';
res = DNS.new;
assert(res, "new() returned something");
assert(res.config.nameserver, "nameservers() works");
servers = res.config.nameserver;
assert_equal(servers[0], '10.0.1.128', 'Nameserver set correctly');
assert_equal(servers[1], '10.0.2.128', 'Nameserver set correctly');
search = res.searchlist;
assert_equal(search[0], 'dnsruby.validation-test-servers.nominet.org.uk', 'Search set correctly' );
assert_equal(search[1], 'lib.dnsruby.validation-test-servers.nominet.org.uk', 'Search set correctly' );
assert_equal(res.domain, 't.dnsruby.validation-test-servers.nominet.org.uk', 'Local domain works' );
assert_equal(3, res.retrans, 'Retransmit works' );
assert_equal(2, res.retry, 'Retry works' );
assert(res.debug, 'Debug works' );
end
|
@todo@ Dnsruby does not provide this functionality
|
test_res_env
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_res_env.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_res_env.rb
|
Apache-2.0
|
def test_decode_opt
# Create an OPT RR
size=2048;
ednsflags=0x9e22;
optrr = RR::OPT.new(size, ednsflags)
# Add it to a message
m = Message.new
m.add_additional(optrr)
# Encode the message
data = m.encode
# Decode it
m2 = Message.decode(data)
# Make sure there is an OPT RR there
assert(m2.rcode == RCode.NOERROR )
end
|
Sadly Nominet no longer host these servers :-(
def test_large_packet
# Query TXT for overflow.dnsruby.validation-test-servers.nominet.org.uk
# with a large udp_size
res = SingleResolver.new
res.udp_size = 4096
ret = res.query("overflow.dnsruby.validation-test-servers.nominet.org.uk", Types.TXT)
assert(ret.rcode == RCode.NoError)
end
|
test_decode_opt
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_rr-opt.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_rr-opt.rb
|
Apache-2.0
|
def test_hash_ignores_ttl
a1 = RR.new_from_string 'techhumans.com. 1111 IN A 69.89.31.97'
a2 = RR.new_from_string 'techhumans.com. 1111 IN A 69.89.31.97'
a3 = RR.new_from_string 'techhumans.com. 2222 IN A 69.89.31.97'
assert_equal a1.hash, a2.hash
assert_equal a1.hash, a3.hash
end
|
TTL should be ignored when calculating the hash of an RR.
|
test_hash_ignores_ttl
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_rr.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_rr.rb
|
Apache-2.0
|
def test_res_config
res = Dnsruby::SingleResolver.new
res.server=('a.t.net-dns.org')
ip = res.server
assert_equal('10.0.1.128', ip.to_s, 'nameserver() looks up IP.')
res.server=('cname.t.net-dns.org')
ip = res.server
assert_equal('10.0.1.128', ip.to_s, 'nameserver() looks up cname.')
end
|
test_queries
@TODO@ Although the test_thread_stopped test runs in isolation, it won't run as part
of the whole test suite (ts_dnsruby.rb). Commented out until I can figure out how to
get Test::Unit to run this one sequentially...
def test_thread_stopped
res=SingleResolver.new
# Send a query, and check select_thread running.
m = res.query("example.com")
assert(Dnsruby::SelectThread.instance.select_thread_alive?)
# Wait a second, and check select_thread stopped.
sleep(2)
assert(!Dnsruby::SelectThread.instance.select_thread_alive?)
# Send another query, and check select_thread running.
m = res.query("example.com")
assert(Dnsruby::SelectThread.instance.select_thread_alive?)
end
|
test_res_config
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_single_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_single_resolver.rb
|
Apache-2.0
|
def test_illegal_src_port
# Try to set src_port to an illegal value - make sure error raised, and port OK
res = SingleResolver.new
tests = [53, 387, 1265, 3210, 48619]
tests.each do |bad_port|
begin
res.src_port = bad_port
fail("bad port #{bad_port}")
rescue
end
end
end
|
def test_truncated_response
res = SingleResolver.new
# print "Dnssec = #{res.dnssec}\n"
# res.server=('ns0.validation-test-servers.nominet.org.uk')
res.server=('ns.nlnetlabs.nl')
res.packet_timeout = 15
begin
m = res.query("overflow.net-dns.org", 'txt')
assert(m.header.ancount == 62, "62 answer records expected, got #{m.header.ancount}")
assert(!m.header.tc, "Message was truncated!")
rescue ResolvTimeout => e
rescue ServFail => e # not sure why, but we get this on Travis...
end
end
|
test_illegal_src_port
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_single_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_single_resolver.rb
|
Apache-2.0
|
def send_async_messages(number_of_messages, queue, wait_seconds = 0)
Dnsruby.log.debug "Sending #{number_of_messages} messages"
number_of_messages.times do
name = "#{self.class.query_id}.com"
Dnsruby.log.debug "Sending #{name}"
message = Dnsruby::Message.new(name)
# self.class.query_id identifies our query, must be different for each message
@@resolver.send_async(message, queue, self.class.query_id)
self.class.query_id += 1
# Note: For 0, we don't sleep at all instead of sleeping 0 since sleeping 0
# involves yielding the CPU.
sleep wait_seconds unless wait_seconds == 0
end
end
|
Send x number of queries asynchronously to our resolver
|
send_async_messages
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
Apache-2.0
|
def test_TCP_pipelining_timeout
return
Dnsruby.log.debug "test_TCP_pipelining_timeout"
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
accept_count = TCPPipeliningServer.stats.accept_count
timeout_count = TCPPipeliningServer.stats.timeout_count
# This is the main queue used to communicate between Dnsruby in async mode and the client
query_queue = Queue.new
# Test basic pipelining. All request should go on the same tcp connection.
# TCPPipeliningServer.stats.accept_count should be 1.
send_async_messages(3, query_queue)
verify_responses(3, query_queue)
assert_equal(accept_count + 1, TCPPipeliningServer.stats.accept_count)
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
timeout_wait(timeout_count + 1, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
assert_equal(timeout_count + 1, TCPPipeliningServer.stats.timeout_count)
# Initiate another 3 queries, check accept_count and timeout_count
send_async_messages(3, query_queue)
verify_responses(3, query_queue)
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
timeout_wait(timeout_count + 2, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
assert_equal(accept_count + 2, TCPPipeliningServer.stats.accept_count)
assert_equal(timeout_count + 2, TCPPipeliningServer.stats.timeout_count)
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
end
|
This test initiates multiple asynchronous requests and verifies they go on the same tcp
pipeline or a new one depending on timeouts
|
test_TCP_pipelining_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
Apache-2.0
|
def test_TCP_pipelining_timeout_in_send
return
Dnsruby.log.debug "test_TCP_pipelining_timeout_in_send"
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
accept_count = TCPPipeliningServer.stats.accept_count
timeout_count = TCPPipeliningServer.stats.timeout_count
query_queue = Queue.new
# Initiate another 2 queries wait and then send a final query
# Check accept_count. Wait for timeout and verify we got 2 additional timeouts.
send_async_messages(2, query_queue)
verify_responses(2, query_queue)
accept_wait(accept_count+1, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
send_async_messages(1, query_queue)
verify_responses(1, query_queue)
assert_equal(accept_count + 2, TCPPipeliningServer.stats.accept_count)
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
timeout_wait(timeout_count + 2, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
end
|
Test timeout occurs and new connection is initiated inbetween 2 sends
|
test_TCP_pipelining_timeout_in_send
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
Apache-2.0
|
def test_TCP_pipelining_socket_eof
return
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
query_queue = Queue.new
# Issue 6 queries. Only 4 should be replied since max_request_per_connection = 4
# Verify we get Dnsruby::SocketEofResolvError on the last 2.
# Verify we got max_count was incremented
send_async_messages(6, query_queue)
responses = []
6.times do
response = query_queue.pop
responses << response
end
responses.sort_by { |response| response[0] }
step = 0
responses.each do | response |
_response_id, response, exception = response
if step < TCPPipeliningServer::DEFAULT_MAX_REQUESTS
assert_nil(exception, "Exception not nil for msg #{step} < #{TCPPipeliningServer::DEFAULT_MAX_REQUESTS} requests")
assert(response.is_a?(Dnsruby::Message))
else
assert_equal(Dnsruby::SocketEofResolvError, exception.class)
assert_nil(response)
end
step += 1
end
connection_wait(0, TCPPipeliningServer::DEFAULT_TIMEOUT*5)
end
|
Test that we get a SocketEofResolvError if the servers closes the socket before
all queries are answered
|
test_TCP_pipelining_socket_eof
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tcp_pipelining.rb
|
Apache-2.0
|
def run_test_client_signs
# NOTE - client signing is only appropriate if DNSSEC and EDNS are switched
# off. Otherwise, the resolver will attempt to alter the flags and add an
# EDNS OPT psuedo-record to the query message, invalidating the signing.
tsig = Dnsruby::RR.create({
:name => KEY_NAME,
:type => "TSIG",
:ttl => 0,
:klass => "ANY",
:algorithm => "hmac-md5",
:fudge => 300,
:key => KEY,
:error => 0
})
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
# Generate update record name, and test it has been made. Then delete it and check it has been deleted
update_name = generate_update_name
update.absent(update_name)
update.add(update_name, 'TXT', 100, "test signed update")
tsig.apply(update)
assert(update.signed?, "Update has not been signed")
res = Dnsruby::Resolver.new("ns0.validation-test-servers.nominet.org.uk")
res.udp_size=512 # Or else we needed to add OPT record already
res.dnssec=false
res.recurse=false
res.query_timeout = 20
response = res.send_message(update)
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
assert(response.verified?, "Response has not been verified")
# Now check the record exists
rr = res.query(update_name, 'TXT')
assert_equal("test signed update", rr.answer()[0].strings.join(" "), "TXT record has not been created in zone")
# Now delete the record
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
update.present(update_name, 'TXT')
update.delete(update_name)
tsig.apply(update)
assert(update.signed?, "Update has not been signed")
response = res.send_message(update)
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
assert(response.verified?, "Response has not been verified")
# Now check the record does not exist
Dnsruby::PacketSender.clear_caches
# Or else the cache will tell us it still deos!
begin
rr = res.query(update_name, 'TXT')
assert(false)
rescue Dnsruby::NXDomain
end
end
|
def test_signed_update_em
begin
Dnsruby::Resolver::use_eventmachine(true)
rescue RuntimeError
Dnsruby.log.error("EventMachine not installed - not running tsig EM tests")
return
end
run_test_client_signs
run_test_resolver_signs
Dnsruby::Resolver::use_eventmachine(false)
end
|
run_test_client_signs
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tsig.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tsig.rb
|
Apache-2.0
|
def ixfr
# Check the SOA serial, do an update, check that the IXFR for that soa serial gives us the update we did,
# then delete the updated record
start_soa_serial = get_soa_serial("validation-test-servers.nominet.org.uk")
# Now do an update
res = Dnsruby::Resolver.new("ns0.validation-test-servers.nominet.org.uk")
res.query_timeout=10
res.tsig=KEY_NAME, KEY
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
# Generate update record name, and test it has been made. Then delete it and check it has been deleted
update_name = Time.now.to_i.to_s + rand(100).to_s + ".update.validation-test-servers.nominet.org.uk"
update.absent(update_name)
update.add(update_name, 'TXT', 100, "test zone transfer")
assert(!update.signed?, "Update has been signed")
response = res.send_message(update)
assert(response.rcode == Dnsruby::RCode.NOERROR)
end_soa_serial = get_soa_serial("validation-test-servers.nominet.org.uk")
zt = Dnsruby::ZoneTransfer.new
zt.transfer_type = Dnsruby::Types.IXFR
zt.server = "ns0.validation-test-servers.nominet.org.uk"
zt.serial = start_soa_serial # 2007090401
deltas = zt.transfer("validation-test-servers.nominet.org.uk")
assert(deltas.length > 0)
assert(deltas.last.class == Dnsruby::ZoneTransfer::Delta)
assert_equal("test zone transfer", deltas.last.adds.last.strings.join(" "))
assert(zt.last_tsigstate==nil)
# Now delete the updated record
update = Dnsruby::Update.new("validation-test-servers.nominet.org.uk")
update.present(update_name, 'TXT')
update.delete(update_name)
response = res.send_message(update)
assert_equal( Dnsruby::RCode.NOERROR, response.rcode)
end
|
We also test IXFR here - this is because we need to update a record (using
TSIG) before we can test ixfr...
|
ixfr
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tsig.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/tc_tsig.rb
|
Apache-2.0
|
def assert_not_raised(exception_class, failure_message = nil)
begin
yield
rescue => e
if e.is_a?(exception_class)
flunk(failure_message || "An exception was not expected but was raised: #{e}")
else
raise e
end
end
end
|
Asserts that all exceptions whose type are the specified exception class
or one of its subclasses are *not* raised.
If any other kind of exception is raised, the test throws an exception
(rather than failing).
The test passes if and only if no exceptions are raised.
|
assert_not_raised
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/test_utils.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/test_utils.rb
|
Apache-2.0
|
def online?
sock = UDPSocket.new()
online = false
begin
sock.connect('193.0.14.129', 25) # that address is k.root-servers.net
online = true
sock.close
rescue Exception => exception
puts "
------------------------------------------------------------
Cannot bind to socket:
#{exception}
This is an indication you have network problems.
No online tests will be run!!
------------------------------------------------------------
"
end
online
end
|
Tells whether or not we can connect to the Internet.
|
online?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/ts_online.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/dnsruby-1.70.0/test/ts_online.rb
|
Apache-2.0
|
def close(code = nil, body = nil)
if code && !acceptable_close_code?(code)
raise "Application code may only use codes from 1000, 3000-4999"
end
close_websocket_private(code, body)
end
|
Use this method to close the websocket connection cleanly
This sends a close frame and waits for acknowlegement before closing
the connection
|
close
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def send_text(data)
# If we're using Ruby 1.9, be pedantic about encodings
if ENCODING_SUPPORTED
# Also accept ascii only data in other encodings for convenience
unless (data.encoding == UTF8 && data.valid_encoding?) || data.ascii_only?
raise WebSocketError, "Data sent to WebSocket must be valid UTF-8 but was #{data.encoding} (valid: #{data.valid_encoding?})"
end
# This labels the encoding as binary so that it can be combined with
# the BINARY framing
data.force_encoding(BINARY)
else
# TODO: Check that data is valid UTF-8
end
if @handler
@handler.send_text_frame(data)
else
raise WebSocketError, "Cannot send data before onopen callback"
end
# Revert data back to the original encoding (which we assume is UTF-8)
# Doing this to avoid duping the string - there may be a better way
data.force_encoding(UTF8) if ENCODING_SUPPORTED
return nil
end
|
Send a WebSocket text frame.
A WebSocketError may be raised if the connection is in an opening or a
closing state, or if the passed in data is not valid UTF-8
|
send_text
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def ping(body = '')
if @handler
@handler.pingable? ? @handler.send_frame(:ping, body) && true : false
else
raise WebSocketError, "Cannot ping before onopen callback"
end
end
|
Send a ping to the client. The client must respond with a pong.
In the case that the client is running a WebSocket draft < 01, false
is returned since ping & pong are not supported
|
ping
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def pong(body = '')
if @handler
@handler.pingable? ? @handler.send_frame(:pong, body) && true : false
else
raise WebSocketError, "Cannot ping before onopen callback"
end
end
|
Send an unsolicited pong message, as allowed by the protocol. The
client is not expected to respond to this message.
em-websocket automatically takes care of sending pong replies to
incoming ping messages, as the protocol demands.
|
pong
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def pingable?
if @handler
@handler.pingable?
else
raise WebSocketError, "Cannot test whether pingable before onopen callback"
end
end
|
Test whether the connection is pingable (i.e. the WebSocket draft in
use is >= 01)
|
pingable?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def max_frame_size
defined?(@max_frame_size) ? @max_frame_size : WebSocket.max_frame_size
end
|
Returns the maximum frame size which this connection is configured to
accept. This can be set globally or on a per connection basis, and
defaults to a value of 10MB if not set.
The behaviour when a too large frame is received varies by protocol,
but in the newest protocols the connection will be closed with the
correct close code (1009) immediately after receiving the frame header
|
max_frame_size
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def abort(reason)
debug [:abort, reason]
close_connection
end
|
As definited in draft 06 7.2.2, some failures require that the server
abort the websocket connection rather than close cleanly
|
abort
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def acceptable_close_code?(code)
case code
when 1000, 1003, 1008, 1011, (3000..4999)
true
else
false
end
end
|
Allow applications to close with 1000, 1003, 1008, 1011, 3xxx or 4xxx.
em-websocket uses a few other codes internally which should not be
used by applications
Browsers generally allow connections to be closed with code 1000,
3xxx, and 4xxx. em-websocket allows closing with a few other codes
which seem reasonable (for discussion see
https://github.com/igrigorik/em-websocket/issues/98)
Usage from the rfc:
1000 indicates a normal closure
1003 indicates that an endpoint is terminating the connection
because it has received a type of data it cannot accept
1008 indicates that an endpoint is terminating the connection because
it has received a message that violates its policy
1011 indicates that a server is terminating the connection because it
encountered an unexpected condition that prevented it from fulfilling
the request
Status codes in the range 3000-3999 are reserved for use by libraries,
frameworks, and applications
Status codes in the range 4000-4999 are reserved for private use and
thus can't be registered
|
acceptable_close_code?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/connection.rb
|
Apache-2.0
|
def send_text_frame(data)
debug [:sending_text_frame, data]
ary = ["\x00", data, "\xff"]
ary.collect{ |s| s.force_encoding('UTF-8') if s.respond_to?(:force_encoding) }
@connection.send_data(ary.join)
end
|
frames need to start with 0x00-0x7f byte and end with
an 0xFF byte. Per spec, we can also set the first
byte to a value betweent 0x80 and 0xFF, followed by
a leading length indicator
|
send_text_frame
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/framing76.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/framing76.rb
|
Apache-2.0
|
def start_close_timeout
@close_timer = EM::Timer.new(@connection.close_timeout) {
@connection.close_connection
e = WSProtocolError.new("Close handshake un-acked after #{@connection.close_timeout}s, closing tcp connection")
@connection.trigger_on_error(e)
}
end
|
Used to avoid un-acked and unclosed remaining open indefinitely
|
start_close_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handler.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handler.rb
|
Apache-2.0
|
def fail_websocket(e)
debug [:error, e]
close_websocket(e.code, e.message)
@connection.close_connection_after_writing
@connection.trigger_on_error(e)
end
|
This corresponds to "Fail the WebSocket Connection" in the spec.
|
fail_websocket
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handler.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handler.rb
|
Apache-2.0
|
def initialize(secure)
@parser = Http::Parser.new
@secure = secure
@parser.on_headers_complete = proc { |headers|
@headers = Hash[headers.map { |k,v| [k.downcase, v] }]
}
end
|
Unfortunately drafts 75 & 76 require knowledge of whether the
connection is being terminated as ws/wss in order to generate the
correct handshake response
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handshake.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handshake.rb
|
Apache-2.0
|
def origin
@headers["origin"] || @headers["sec-websocket-origin"] || nil
end
|
Returns the WebSocket origin header if provided
|
origin
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handshake.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/handshake.rb
|
Apache-2.0
|
def read_mask
if respond_to?(:encoding) && encoding.name != "ASCII-8BIT"
raise "MaskedString only operates on BINARY strings"
end
raise "Too short" if bytesize < 4 # TODO - change
@masking_key = String.new(self[0..3])
end
|
Read a 4 bit XOR mask - further requested bytes will be unmasked
|
read_mask
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/masking04.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/masking04.rb
|
Apache-2.0
|
def unset_mask
@masking_key = nil
end
|
Removes the mask, behaves like a normal string again
|
unset_mask
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/masking04.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/em-websocket-0.5.3/lib/em-websocket/masking04.rb
|
Apache-2.0
|
def init
@@curl_mutex.synchronize {
if not @@initialized
raise Errors::GlobalInit.new if Curl.global_init(GLOBAL_ALL) != 0
@@initialized = true
Ethon.logger.debug("ETHON: Libcurl initialized") if Ethon.logger
end
}
end
|
This function sets up the program environment that libcurl needs.
Think of it as an extension of the library loader.
This function must be called at least once within a program (a program is all the
code that shares a memory space) before the program calls any other function in libcurl.
The environment it sets up is constant for the life of the program and is the same for
every program, so multiple calls have the same effect as one call.
The flags option is a bit pattern that tells libcurl exactly what features to init,
as described below. Set the desired bits by ORing the values together. In normal
operation, you must specify CURL_GLOBAL_ALL. Don't use any other value unless
you are familiar with it and mean to control internal operations of libcurl.
This function is not thread safe. You must not call it when any other thread in
the program (i.e. a thread sharing the same memory) is running. This doesn't just
mean no other thread that is using libcurl. Because curl_global_init() calls
functions of other libraries that are similarly thread unsafe, it could conflict with
any other thread that uses these other libraries.
@raise [ Ethon::Errors::GlobalInit ] If Curl.global_init fails.
|
init
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curl.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curl.rb
|
Apache-2.0
|
def cleanup
@@curl_mutex.synchronize {
if @@initialized
Curl.global_cleanup()
@@initialized = false
Ethon.logger.debug("ETHON: Libcurl cleanup") if Ethon.logger
end
}
end
|
This function releases resources acquired by curl_global_init.
You should call curl_global_cleanup once for each call you make to
curl_global_init, after you are done using libcurl.
This function is not thread safe. You must not call it when any other thread in the
program (i.e. a thread sharing the same memory) is running. This doesn't just
mean no other thread that is using libcurl. Because curl_global_cleanup calls functions of other
libraries that are similarly thread unsafe, it could conflict with
any other thread that uses these other libraries.
See the description in libcurl of global environment requirements
for details of how to use this function.
|
cleanup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curl.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curl.rb
|
Apache-2.0
|
def initialize(options = {})
Curl.init
set_attributes(options)
set_callbacks
end
|
Initialize a new Easy.
It initializes curl, if not already done and applies the provided options.
Look into {Ethon::Easy::Options Options} to see what you can provide in the
options hash.
@example Create a new Easy.
Easy.new(url: "www.google.de")
@param [ Hash ] options The options to set.
@option options :headers [ Hash ] Request headers.
@return [ Easy ] A new Easy.
@see Ethon::Easy::Options
@see http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def set_attributes(options)
options.each_pair do |key, value|
method = "#{key}="
unless respond_to?(method)
raise Errors::InvalidOption.new(key)
end
send(method, value)
end
end
|
Set given options.
@example Set options.
easy.set_attributes(options)
@param [ Hash ] options The options.
@raise InvalidOption
@see initialize
|
set_attributes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def reset
@url = nil
@escape = nil
@hash = nil
@on_complete = nil
@on_headers = nil
@on_body = nil
@on_progress = nil
@procs = nil
@mirror = nil
Curl.easy_reset(handle)
set_callbacks
end
|
Reset easy. This means resetting all options and instance variables.
Also the easy handle is resetted.
@example Reset.
easy.reset
|
reset
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def dup
e = super
e.handle = Curl.easy_duphandle(handle)
e.instance_variable_set(:@body_write_callback, nil)
e.instance_variable_set(:@header_write_callback, nil)
e.instance_variable_set(:@debug_callback, nil)
e.instance_variable_set(:@progress_callback, nil)
e.set_callbacks
e
end
|
Clones libcurl session handle. This means that all options that is set in
the current handle will be set on duplicated handle.
|
dup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def escape(value)
string_pointer = Curl.easy_escape(handle, value, value.bytesize)
returned_string = string_pointer.read_string
Curl.free(string_pointer)
returned_string
end
|
Url escapes the value.
@example Url escape.
easy.escape(value)
@param [ String ] value The value to escape.
@return [ String ] The escaped value.
@api private
|
escape
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def to_hash
Kernel.warn("Ethon: Easy#to_hash is deprecated and will be removed, please use #mirror.")
mirror.to_hash
end
|
Returns the informations available through libcurl as
a hash.
@return [ Hash ] The informations hash.
|
to_hash
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def log_inspect
"EASY #{mirror.log_informations.map{|k, v| "#{k}=#{v}"}.flatten.join(' ')}"
end
|
Return pretty log out.
@example Return log out.
easy.log_inspect
@return [ String ] The log out.
|
log_inspect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy.rb
|
Apache-2.0
|
def logger
return @logger if defined?(@logger)
@logger = rails_logger || default_logger
end
|
Get the logger.
@note Will try to grab Rails' logger first before creating a new logger
with stdout.
@example Get the logger.
Loggable.logger
@return [ Logger ] The logger.
|
logger
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/loggable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/loggable.rb
|
Apache-2.0
|
def default_logger
logger = Logger.new($stdout)
logger.level = Logger::INFO
logger
end
|
Gets the default Ethon logger - stdout.
@example Get the default logger.
Loggable.default_logger
@return [ Logger ] The default logger.
|
default_logger
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/loggable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/loggable.rb
|
Apache-2.0
|
def rails_logger
defined?(::Rails) && ::Rails.respond_to?(:logger) && ::Rails.logger
end
|
Get the Rails logger if it's defined.
@example Get Rails' logger.
Loggable.rails_logger
@return [ Logger ] The Rails logger.
|
rails_logger
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/loggable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/loggable.rb
|
Apache-2.0
|
def set_attributes(options)
options.each_pair do |key, value|
unless respond_to?("#{key}=")
raise Errors::InvalidOption.new(key)
end
method("#{key}=").call(value)
end
end
|
Set given options.
@example Set options.
multi.set_attributes(options)
@raise InvalidOption
@see initialize
@api private
|
set_attributes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi.rb
|
Apache-2.0
|
def ensure_execution_mode(expected_mode)
raise ArgumentError, "Expected the Multi to be in #{expected_mode} but it was in #{@execution_mode}" if expected_mode != @execution_mode
end
|
Internal function to gate functions to a specific execution mode
@raise ArgumentError
@api private
|
ensure_execution_mode
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi.rb
|
Apache-2.0
|
def easy_codes
[
:ok,
:unsupported_protocol,
:failed_init,
:url_malformat,
:not_built_in,
:couldnt_resolve_proxy,
:couldnt_resolve_host,
:couldnt_connect,
:ftp_weird_server_reply,
:remote_access_denied,
:ftp_accept_failed,
:ftp_weird_pass_reply,
:ftp_accept_timeout,
:ftp_weird_pasv_reply,
:ftp_weird_227_format,
:ftp_cant_get_host,
:obsolete16,
:ftp_couldnt_set_type,
:partial_file,
:ftp_couldnt_retr_file,
:obsolete20,
:quote_error,
:http_returned_error,
:write_error,
:obsolete24,
:upload_failed,
:read_error,
:out_of_memory,
:operation_timedout,
:obsolete29,
:ftp_port_failed,
:ftp_couldnt_use_rest,
:obsolete32,
:range_error,
:http_post_error,
:ssl_connect_error,
:bad_download_resume,
:file_couldnt_read_file,
:ldap_cannot_bind,
:ldap_search_failed,
:obsolete40,
:function_not_found,
:aborted_by_callback,
:bad_function_argument,
:obsolete44,
:interface_failed,
:obsolete46,
:too_many_redirects ,
:unknown_option,
:telnet_option_syntax ,
:obsolete50,
:peer_failed_verification,
:got_nothing,
:ssl_engine_notfound,
:ssl_engine_setfailed,
:send_error,
:recv_error,
:obsolete57,
:ssl_certproblem,
:ssl_cipher,
:bad_content_encoding,
:ldap_invalid_url,
:filesize_exceeded,
:use_ssl_failed,
:send_fail_rewind,
:ssl_engine_initfailed,
:login_denied,
:tftp_notfound,
:tftp_perm,
:remote_disk_full,
:tftp_illegal,
:tftp_unknownid,
:remote_file_exists,
:tftp_nosuchuser,
:conv_failed,
:conv_reqd,
:ssl_cacert_badfile,
:remote_file_not_found,
:ssh,
:ssl_shutdown_failed,
:again,
:ssl_crl_badfile,
:ssl_issuer_error,
:ftp_pret_failed,
:rtsp_cseq_error,
:rtsp_session_error,
:ftp_bad_file_list,
:chunk_failed,
:last
]
end
|
Libcurl error codes, refer
https://github.com/bagder/curl/blob/master/include/curl/curl.h for details
|
easy_codes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/codes.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/codes.rb
|
Apache-2.0
|
def multi_codes
[
:call_multi_perform, -1,
:ok,
:bad_handle,
:bad_easy_handle,
:out_of_memory,
:internal_error,
:bad_socket,
:unknown_option,
:last
]
end
|
Curl-Multi socket error codes, refer
https://github.com/bagder/curl/blob/master/include/curl/multi.h for details
|
multi_codes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/codes.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/codes.rb
|
Apache-2.0
|
def form_options
[
:none,
:copyname,
:ptrname,
:namelength,
:copycontents,
:ptrcontents,
:contentslength,
:filecontent,
:array,
:obsolete,
:file,
:buffer,
:bufferptr,
:bufferlength,
:contenttype,
:contentheader,
:filename,
:end,
:obsolete2,
:stream,
:last
]
end
|
Form options, used by FormAdd for temporary storage, refer
https://github.com/bagder/curl/blob/master/lib/formdata.h#L51 for details
|
form_options
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/form_options.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/form_options.rb
|
Apache-2.0
|
def info_types
{
:string =>0x100000,
:long => 0x200000,
:double =>0x300000,
:slist => 0x400000
}
end
|
Return info types.
@example Return info types.
Ethon::Curl.info_types
@return [ Hash ] The info types.
|
info_types
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
Apache-2.0
|
def debug_info_types
[
:text, 0,
:header_in,
:header_out,
:data_in,
:data_out,
:ssl_data_in,
:ssl_data_out
]
end
|
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTDEBUGFUNCTION
https://github.com/bagder/curl/blob/master/include/curl/curl.h#L378
@example Return debug info types.
Ethon::Curl.debug_info_types
@return [ Hash ] The info types available to curl_debug_callback.
|
debug_info_types
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
Apache-2.0
|
def infos
{
:effective_url => info_types[:string] + 1,
:response_code => info_types[:long] + 2,
:total_time => info_types[:double] + 3,
:namelookup_time => info_types[:double] + 4,
:connect_time => info_types[:double] + 5,
:pretransfer_time => info_types[:double] + 6,
:size_upload => info_types[:double] + 7,
:size_download => info_types[:double] + 8,
:speed_download => info_types[:double] + 9,
:speed_upload => info_types[:double] + 10,
:header_size => info_types[:long] + 11,
:request_size => info_types[:long] + 12,
:ssl_verifyresult => info_types[:long] + 13,
:filetime => info_types[:long] + 14,
:content_length_download =>info_types[:double] + 15,
:content_length_upload => info_types[:double] + 16,
:starttransfer_time => info_types[:double] + 17,
:content_type => info_types[:string] + 18,
:redirect_time => info_types[:double] + 19,
:redirect_count => info_types[:long] + 20,
:private => info_types[:string] + 21,
:http_connectcode => info_types[:long] + 22,
:httpauth_avail => info_types[:long] + 23,
:proxyauth_avail => info_types[:long] + 24,
:os_errno => info_types[:long] + 25,
:num_connects => info_types[:long] + 26,
:ssl_engines => info_types[:slist] + 27,
:cookielist => info_types[:slist] + 28,
:lastsocket => info_types[:long] + 29,
:ftp_entry_path => info_types[:string] + 30,
:redirect_url => info_types[:string] + 31,
:primary_ip => info_types[:string] + 32,
:appconnect_time => info_types[:double] + 33,
:certinfo => info_types[:slist] + 34,
:condition_unmet => info_types[:long] + 35,
:rtsp_session_id => info_types[:string] + 36,
:rtsp_client_cseq => info_types[:long] + 37,
:rtsp_server_cseq => info_types[:long] + 38,
:rtsp_cseq_recv => info_types[:long] + 39,
:primary_port => info_types[:long] + 40,
:local_ip => info_types[:string] + 41,
:local_port => info_types[:long] + 42,
:last =>42
}
end
|
Return Info details, refer
https://github.com/bagder/curl/blob/master/src/tool_writeout.c#L66 for details
@example Return infos.
Ethon::Curl.infos
@return [ Hash ] The infos.
|
infos
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
Apache-2.0
|
def get_info_string(option, handle)
string_ptr = ::FFI::MemoryPointer.new(:pointer)
if easy_getinfo(handle, option, :pointer, string_ptr) == :ok
ptr=string_ptr.read_pointer
ptr.null? ? nil : ptr.read_string
end
end
|
Return info as string.
@example Return info.
Curl.get_info_string(:primary_ip, easy)
@param [ Symbol ] option The option name.
@param [ ::FFI::Pointer ] handle The easy handle.
@return [ String ] The info.
|
get_info_string
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
Apache-2.0
|
def get_info_long(option, handle)
long_ptr = ::FFI::MemoryPointer.new(:long)
if easy_getinfo(handle, option, :pointer, long_ptr) == :ok
long_ptr.read_long
end
end
|
Return info as integer.
@example Return info.
Curl.get_info_long(:response_code, easy)
@param [ Symbol ] option The option name.
@param [ ::FFI::Pointer ] handle The easy handle.
@return [ Integer ] The info.
|
get_info_long
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
Apache-2.0
|
def get_info_double(option, handle)
double_ptr = ::FFI::MemoryPointer.new(:double)
if easy_getinfo(handle, option, :pointer, double_ptr) == :ok
double_ptr.read_double
end
end
|
Return info as float
@example Return info.
Curl.get_info_double(:response_code, easy)
@param [ Symbol ] option The option name.
@param [ ::FFI::Pointer ] handle The easy handle.
@return [ Float ] The info.
|
get_info_double
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/infos.rb
|
Apache-2.0
|
def msg_codes
[:none, :done, :last]
end
|
Return message codes.
@example Return message codes.
Ethon::Curl.msg_codes
@return [ Array ] The messages codes.
|
msg_codes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/messages.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/messages.rb
|
Apache-2.0
|
def set_option(option, value, handle, type = :easy)
type = type.to_sym unless type.is_a?(Symbol)
raise NameError, "Ethon::Curls::Options unknown type #{type}." unless respond_to?(OPTION_STRINGS[type])
opthash=send(OPTION_STRINGS[type], nil)
raise Errors::InvalidOption.new(option) unless opthash.include?(option)
case opthash[option][:type]
when :none
return if value.nil?
value=1
va_type=:long
when :int
return if value.nil?
va_type=:long
value=value.to_i
when :bool
return if value.nil?
va_type=:long
value=(value&&value!=0) ? 1 : 0
when :time
return if value.nil?
va_type=:long
value=value.to_i
when :enum
return if value.nil?
va_type=:long
value = case value
when Symbol
opthash[option][:opts][value]
when String
opthash[option][:opts][value.to_sym]
else
value
end.to_i
when :bitmask
return if value.nil?
va_type=:long
value = case value
when Symbol
opthash[option][:opts][value]
when Array
value.inject(0) { |res,v| res|opthash[option][:opts][v] }
else
value
end.to_i
when :string
va_type=:string
value=value.to_s unless value.nil?
when :string_as_pointer
va_type = :pointer
s = ''
s = value.to_s unless value.nil?
value = FFI::MemoryPointer.new(:char, s.bytesize)
value.put_bytes(0, s)
when :string_escape_null
va_type=:string
value=Util.escape_zero_byte(value) unless value.nil?
when :ffipointer
va_type=:pointer
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? FFI::Pointer
when :curl_slist
va_type=:pointer
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? FFI::Pointer
when :buffer
raise NotImplementedError, "Ethon::Curls::Options option #{option} buffer type not implemented."
when :dontuse_object
raise NotImplementedError, "Ethon::Curls::Options option #{option} type not implemented."
when :cbdata
raise NotImplementedError, "Ethon::Curls::Options option #{option} callback data type not implemented. Use Ruby closures."
when :callback
va_type=:callback
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
when :socket_callback
va_type=:socket_callback
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
when :timer_callback
va_type=:timer_callback
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
when :debug_callback
va_type=:debug_callback
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
when :progress_callback
va_type=:progress_callback
raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
when :off_t
return if value.nil?
va_type=:int64
value=value.to_i
end
if va_type==:long or va_type==:int64 then
bits=FFI.type_size(va_type)*8
tv=((value<0) ? value.abs-1 : value)
raise Errors::InvalidValue.new(option,value) unless tv<(1<<bits)
end
send(FUNCS[type], handle, opthash[option][:opt], va_type, value)
end
|
Sets appropriate option for easy, depending on value type.
|
set_option
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/options.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/curls/options.rb
|
Apache-2.0
|
def set_callbacks
Curl.set_option(:writefunction, body_write_callback, handle)
Curl.set_option(:headerfunction, header_write_callback, handle)
Curl.set_option(:debugfunction, debug_callback, handle)
@response_body = String.new
@response_headers = String.new
@headers_called = false
@debug_info = Ethon::Easy::DebugInfo.new
end
|
Set writefunction and headerfunction callback.
They are called by libcurl in order to provide the header and
the body from the request.
@example Set callbacks.
easy.set_callbacks
|
set_callbacks
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
Apache-2.0
|
def body_write_callback
@body_write_callback ||= proc do |stream, size, num, object|
headers
result = body(chunk = stream.read_string(size * num))
@response_body << chunk if result == :unyielded
result != :abort ? size * num : -1
end
end
|
Returns the body write callback.
@example Return the callback.
easy.body_write_callback
@return [ Proc ] The callback.
|
body_write_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
Apache-2.0
|
def header_write_callback
@header_write_callback ||= proc {|stream, size, num, object|
result = headers
@response_headers << stream.read_string(size * num)
result != :abort ? size * num : -1
}
end
|
Returns the header write callback.
@example Return the callback.
easy.header_write_callback
@return [ Proc ] The callback.
|
header_write_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
Apache-2.0
|
def debug_callback
@debug_callback ||= proc {|handle, type, data, size, udata|
message = data.read_string(size)
@debug_info.add type, message
print message unless [:data_in, :data_out].include?(type)
0
}
end
|
Returns the debug callback. This callback is currently used
write the raw http request headers.
@example Return the callback.
easy.debug_callback
@return [ Proc ] The callback.
|
debug_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
Apache-2.0
|
def progress_callback
@progress_callback ||= proc { |_, dltotal, dlnow, ultotal, ulnow|
progress(dltotal, dlnow, ultotal, ulnow)
0
}
end
|
Returns the progress callback.
@example Return the callback.
easy.progress_callback
@return [ Proc ] The callback.
|
progress_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
Apache-2.0
|
def set_read_callback(body)
@request_body_read = 0
readfunction do |stream, size, num, object|
size = size * num
body_size = if body.respond_to?(:bytesize)
body.bytesize
elsif body.respond_to?(:size)
body.size
elsif body.is_a?(File)
File.size(body.path)
end
left = body_size - @request_body_read
size = left if size > left
if size > 0
chunk = if body.respond_to?(:byteslice)
body.byteslice(@request_body_read, size)
elsif body.respond_to?(:read)
body.read(size)
else
body[@request_body_read, size]
end
stream.write_string(
chunk, size
)
@request_body_read += size
end
size
end
end
|
Set the read callback. This callback is used by libcurl to
read data when performing a PUT request.
@example Set the callback.
easy.set_read_callback("a=1")
@param [ String ] body The body.
|
set_read_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/callbacks.rb
|
Apache-2.0
|
def supports_zlib?
!!(Curl.version_info[:features] & Curl::VERSION_LIBZ)
end
|
Returns true if this curl version supports zlib.
@example Return wether zlib is supported.
Ethon::Easy.supports_zlib?
@return [ Boolean ] True if supported, else false.
|
supports_zlib?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/features.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/features.rb
|
Apache-2.0
|
def supports_asynch_dns?
!!(Curl.version_info[:features] & Curl::VERSION_ASYNCHDNS)
end
|
Returns true if this curl version supports AsynchDNS.
@example
Ethon::Easy.supports_asynch_dns?
@return [ Boolean ] True if supported, else false.
|
supports_asynch_dns?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/features.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/features.rb
|
Apache-2.0
|
def initialize(easy, params, multipart = nil)
@easy = easy
@params = params || {}
@multipart = multipart
end
|
Return a new Form.
@example Return a new Form.
Form.new({})
@param [ Hash ] params The parameter with which to initialize the form.
@return [ Form ] A new Form.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
Apache-2.0
|
def first
@first ||= FFI::MemoryPointer.new(:pointer)
end
|
Return a pointer to the first form element in libcurl.
@example Return the first form element.
form.first
@return [ FFI::Pointer ] The first element.
|
first
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
Apache-2.0
|
def last
@last ||= FFI::MemoryPointer.new(:pointer)
end
|
Return a pointer to the last form element in libcurl.
@example Return the last form element.
form.last
@return [ FFI::Pointer ] The last element.
|
last
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
Apache-2.0
|
def multipart?
return true if @multipart
query_pairs.any?{|pair| pair.respond_to?(:last) && pair.last.is_a?(Array)}
end
|
Return if form is multipart. The form is multipart
when it contains a file or multipart option is set on the form during creation.
@example Return if form is multipart.
form.multipart?
@return [ Boolean ] True if form is multipart, else false.
|
multipart?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
Apache-2.0
|
def materialize
query_pairs.each { |pair| form_add(pair.first.to_s, pair.last) }
end
|
Add form elements to libcurl.
@example Add form to libcurl.
form.materialize
|
materialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/form.rb
|
Apache-2.0
|
def headers
@headers ||= {}
end
|
Return headers, return empty hash if none.
@example Return the headers.
easy.headers
@return [ Hash ] The headers.
|
headers
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
|
Apache-2.0
|
def compose_header(key, value)
Util.escape_zero_byte("#{key}: #{value}")
end
|
Compose libcurl header string from key and value.
Also replaces null bytes, because libcurl will complain
otherwise.
@example Compose header.
easy.compose_header('User-Agent', 'Ethon')
@param [ String ] key The header name.
@param [ String ] value The header value.
@return [ String ] The composed header.
|
compose_header
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
|
Apache-2.0
|
def http_request(url, action_name, options = {})
fabricate(url, action_name, options).setup(self)
end
|
Set specified options in order to make a HTTP request.
Look at {Ethon::Easy::Options Options} to see what you can
provide in the options hash.
@example Set options for HTTP request.
easy.http_request("www.google.com", :get, {})
@param [ String ] url The url.
@param [ String ] action_name The HTTP action name.
@param [ Hash ] options The options hash.
@option options :params [ Hash ] Params hash which
is attached to the url.
@option options :body [ Hash ] Body hash which
becomes the request body. It is a PUT body for
PUT requests and a POST for everything else.
@option options :headers [ Hash ] Request headers.
@return [ void ]
@see Ethon::Easy::Options
|
http_request
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http.rb
|
Apache-2.0
|
def fabricate(url, action_name, options)
constant_name = action_name.to_s.capitalize
if Ethon::Easy::Http.const_defined?(constant_name)
Ethon::Easy::Http.const_get(constant_name).new(url, options)
else
Ethon::Easy::Http::Custom.new(constant_name.upcase, url, options)
end
end
|
Return the corresponding action class.
@example Return the action.
Action.fabricate(:get)
Action.fabricate(:smash)
@param [ String ] url The url.
@param [ String ] action_name The HTTP action name.
@param [ Hash ] options The option hash.
@return [ Easy::Ethon::Actionable ] The request instance.
|
fabricate
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http.rb
|
Apache-2.0
|
def supports_zlib?
Kernel.warn("Ethon: Easy#supports_zlib? is deprecated and will be removed, please use Easy#.")
Easy.supports_zlib?
end
|
Returns true if this curl version supports zlib.
@example Return wether zlib is supported.
easy.supports_zlib?
@return [ Boolean ] True if supported, else false.
@deprecated Please use the static version instead
|
supports_zlib?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/informations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/informations.rb
|
Apache-2.0
|
def handle
@handle ||= FFI::AutoPointer.new(Curl.easy_init, Curl.method(:easy_cleanup))
end
|
Returns a pointer to the curl easy handle.
@example Return the handle.
easy.handle
@return [ FFI::Pointer ] A pointer to the curl easy handle.
|
handle
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb
|
Apache-2.0
|
def perform
@return_code = Curl.easy_perform(handle)
if Ethon.logger.debug?
Ethon.logger.debug { "ETHON: performed #{log_inspect}" }
end
complete
@return_code
end
|
Perform the easy request.
@example Perform the request.
easy.perform
@return [ Integer ] The return code.
|
perform
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb
|
Apache-2.0
|
def prepare
Ethon.logger.warn(
"ETHON: It is no longer necessary to call "+
"Easy#prepare. It's going to be removed "+
"in future versions."
)
end
|
Prepare the easy. Options, headers and callbacks
were set.
@example Prepare easy.
easy.prepare
@deprecated It is no longer necessary to call prepare.
|
prepare
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/operations.rb
|
Apache-2.0
|
def initialize(easy, params)
@easy = easy
@params = params || {}
end
|
Create a new Params.
@example Create a new Params.
Params.new({})
@param [ Hash ] params The params to use.
@return [ Params ] A new Params.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/params.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/params.rb
|
Apache-2.0
|
def to_s
@to_s ||= query_pairs.map{ |pair|
return pair if pair.is_a?(String)
if escape && @easy
pair.map{ |e| @easy.escape(e.to_s) }.join("=")
else
pair.join("=")
end
}.join('&')
end
|
Return the string representation of params.
@example Return string representation.
params.to_s
@return [ String ] The string representation.
|
to_s
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
Apache-2.0
|
def query_pairs
@query_pairs ||= build_query_pairs(@params)
end
|
Return the query pairs.
@example Return the query pairs.
params.query_pairs
@return [ Array ] The query pairs.
|
query_pairs
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
Apache-2.0
|
def build_query_pairs(hash)
return [hash] if hash.is_a?(String)
pairs = []
recursively_generate_pairs(hash, nil, pairs)
pairs
end
|
Return query pairs build from a hash.
@example Build query pairs.
action.build_query_pairs({a: 1, b: 2})
#=> [[:a, 1], [:b, 2]]
@param [ Hash ] hash The hash to go through.
@return [ Array ] The array of query pairs.
|
build_query_pairs
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
Apache-2.0
|
def file_info(file)
filename = File.basename(file.path)
[
filename,
mime_type(filename),
File.expand_path(file.path)
]
end
|
Return file info for a file.
@example Return file info.
action.file_info(File.open('fubar', 'r'))
@param [ File ] file The file to handle.
@return [ Array ] Array of informations.
|
file_info
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/queryable.rb
|
Apache-2.0
|
def on_headers(&block)
@on_headers ||= []
@on_headers << block if block_given?
@on_headers
end
|
Set on_headers callback.
@example Set on_headers.
request.on_headers { p "yay" }
@param [ Block ] block The block to execute.
|
on_headers
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def headers
return if @headers_called
@headers_called = true
if defined?(@on_headers) and not @on_headers.nil?
result = nil
@on_headers.each do |callback|
result = callback.call(self)
break if result == :abort
end
result
end
end
|
Execute on_headers callbacks.
@example Execute on_headers.
request.headers
|
headers
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def on_complete(&block)
@on_complete ||= []
@on_complete << block if block_given?
@on_complete
end
|
Set on_complete callback.
@example Set on_complete.
request.on_complete { p "yay" }
@param [ Block ] block The block to execute.
|
on_complete
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def complete
headers unless @response_headers.empty?
if defined?(@on_complete) and not @on_complete.nil?
@on_complete.each{ |callback| callback.call(self) }
end
end
|
Execute on_complete callbacks.
@example Execute on_completes.
request.complete
|
complete
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def on_progress(&block)
@on_progress ||= []
if block_given?
@on_progress << block
set_progress_callback
self.noprogress = 0
end
@on_progress
end
|
Set on_progress callback.
@example Set on_progress.
request.on_progress {|dltotal, dlnow, ultotal, ulnow| p "#{dltotal} #{dlnow} #{ultotal} #{ulnow}" }
@param [ Block ] block The block to execute.
|
on_progress
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def progress(dltotal, dlnow, ultotal, ulnow)
if defined?(@on_progress) and not @on_progress.nil?
@on_progress.each{ |callback| callback.call(dltotal, dlnow, ultotal, ulnow) }
end
end
|
Execute on_progress callbacks.
@example Execute on_progress.
request.body(1, 1, 1, 1)
|
progress
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def on_body(&block)
@on_body ||= []
@on_body << block if block_given?
@on_body
end
|
Set on_body callback.
@example Set on_body.
request.on_body { |chunk| p "yay" }
@param [ Block ] block The block to execute.
|
on_body
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def body(chunk)
if defined?(@on_body) and not @on_body.nil?
result = nil
@on_body.each do |callback|
result = callback.call(chunk, self)
break if result == :abort
end
result
else
:unyielded
end
end
|
Execute on_body callbacks.
@example Execute on_body.
request.body("This data came from HTTP.")
@return [ Object ] If there are no on_body callbacks, returns the symbol :unyielded.
|
body
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/response_callbacks.rb
|
Apache-2.0
|
def escape_zero_byte(value)
return value unless value.to_s.include?(0.chr)
value.to_s.gsub(0.chr, '\\\0')
end
|
Escapes zero bytes in strings.
@example Escape zero bytes.
Util.escape_zero_byte("1\0")
#=> "1\\0"
@param [ Object ] value The value to escape.
@return [ String, Object ] Escaped String if
zero byte found, original object if not.
|
escape_zero_byte
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/util.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/util.rb
|
Apache-2.0
|
def initialize(url, options)
@url = url
@options, @query_options = parse_options(options)
end
|
Create a new action.
@example Create a new action.
Action.new("www.example.com", {})
@param [ String ] url The url.
@param [ Hash ] options The options.
@return [ Action ] A new action.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
Apache-2.0
|
def params
@params ||= Params.new(@easy, query_options.fetch(:params, nil))
end
|
Return the params.
@example Return params.
action.params
@return [ Params ] The params.
|
params
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
Apache-2.0
|
def form
@form ||= Form.new(@easy, query_options.fetch(:body, nil), options.fetch(:multipart, nil))
end
|
Return the form.
@example Return form.
action.form
@return [ Form ] The form.
|
form
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
Apache-2.0
|
def params_encoding
@params_encoding ||= query_options.fetch(:params_encoding, :typhoeus)
end
|
Get the requested array encoding. By default it's
:typhoeus, but it can also be set to :rack.
@example Get encoding from options
action.params_encoding
|
params_encoding
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.