How to use perform method of Curl Package

Best Webmock_ruby code snippet using Curl.perform

tc_curl_easy.rb

Source:tc_curl_easy.rb Github

copy

Full Screen

...21 File.open(path, 'w') do |file|22 easy = Curl::Easy.new(TestServlet.url)23 easy.verbose = true24 easy.setopt(Curl::CURLOPT_STDERR, file)25 easy.perform26 end27 output = File.read(path)28 assert_match(/HTTP\/1\.1\ 200\ OK(?:\ )?/, output)29 assert_match('Host: 127.0.0.1:9129', output)30 end31 def test_curlopt_stderr_with_io32 path = Tempfile.new('curb_test_curlopt_stderr').path33 fd = IO.sysopen(path, 'w')34 io = IO.for_fd(fd)35 easy = Curl::Easy.new(TestServlet.url)36 easy.verbose = true37 easy.setopt(Curl::CURLOPT_STDERR, io)38 easy.perform39 output = File.read(path)40 assert_match(output, 'HTTP/1.1 200 OK')41 assert_match(output, 'Host: 127.0.0.1:9129')42 end43 def test_curlopt_stderr_fails_with_tempdir44 Tempfile.open('curb_test_curlopt_stderr') do |tempfile|45 easy = Curl::Easy.new(TestServlet.url)46 assert_raise(TypeError) do47 easy.setopt(Curl::CURLOPT_STDERR, tempfile)48 end49 end50 end51 def test_curlopt_stderr_fails_with_stringio52 stringio = StringIO.new53 easy = Curl::Easy.new(TestServlet.url)54 assert_raise(TypeError) do55 easy.setopt(Curl::CURLOPT_STDERR, stringio)56 end57 end58 def test_curlopt_stderr_fails_with_string59 string = String.new60 easy = Curl::Easy.new(TestServlet.url)61 assert_raise(TypeError) do62 easy.setopt(Curl::CURLOPT_STDERR, string)63 end64 end65 def test_exception66 begin67 Curl.get('NOT_FOUND_URL')68 rescue69 assert true70 rescue Exception71 assert false, "We should raise StandardError"72 end73 end74 def test_threads75 t = []76 5.times do77 t << Thread.new do78 5.times do79 c = Curl.get($TEST_URL)80 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)81 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)82 end83 end84 end85 t.each {|x| x.join }86 end87 def test_class_perform_01 88 assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)89 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)90 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)91 end 92 def test_class_perform_0293 data = ""94 assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } } 95 assert_nil c.body_str96 assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)97 end 98 def test_class_perform_0399 assert_raise(Curl::Err::CouldntReadError) { Curl::Easy.perform($TEST_URL + "nonexistent") }100 end 101 102 def test_new_01103 c = Curl::Easy.new104 assert_equal Curl::Easy, c.class105 assert_nil c.url106 assert_nil c.body_str107 assert_nil c.header_str108 end109 def test_new_02110 c = Curl::Easy.new($TEST_URL)111 assert_equal $TEST_URL, c.url112 end113 114 def test_new_03115 blk = lambda { |i| i.length }116 117 c = Curl::Easy.new do |curl|118 curl.on_body(&blk)119 end120 121 assert_nil c.url 122 assert_equal blk, c.on_body # sets handler nil, returns old handler123 assert_equal nil, c.on_body124 end125 126 def test_new_04127 blk = lambda { |i| i.length }128 129 c = Curl::Easy.new($TEST_URL) do |curl|130 curl.on_body(&blk)131 end132 133 assert_equal $TEST_URL, c.url134 assert_equal blk, c.on_body # sets handler nil, returns old handler135 assert_equal nil, c.on_body136 end137 class Foo < Curl::Easy ; end138 def test_new_05139 # can use Curl::Easy as a base class140 c = Foo.new141 assert_equal Foo, c.class142 c.url = $TEST_URL143 c.perform144 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)145 end146 # test invalid use of new147 def test_new_06148 Curl::Easy.new(TestServlet.url) do|curl|149 curl.http_post150 assert_equal "POST\n", curl.body_str151 end152 end153 def test_escape154 c = Curl::Easy.new155 156 assert_equal "one%20two", c.escape('one two')157 assert_equal "one%00two%20three", c.escape("one\000two three") 158 end159 160 def test_unescape161 c = Curl::Easy.new162 163 assert_equal "one two", c.unescape('one%20two')164 165 # prior to 7.15.4 embedded nulls cannot be unescaped166 if Curl::VERNUM >= 0x070f04167 assert_equal "one\000two three", c.unescape("one%00two%20three")168 end169 end170 171 def test_headers172 c = Curl::Easy.new($TEST_URL)173 174 assert_equal({}, c.headers)175 c.headers = "Expect:"176 assert_equal "Expect:", c.headers177 c.headers = ["Expect:", "User-Agent: myapp-0.0.0"]178 assert_equal ["Expect:", "User-Agent: myapp-0.0.0"], c.headers179 end 180 def test_get_01 181 c = Curl::Easy.new($TEST_URL) 182 assert_equal true, c.http_get183 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)184 end 185 def test_get_02186 data = ""187 c = Curl::Easy.new($TEST_URL) do |curl|188 curl.on_body { |d| data << d; d.length }189 end190 191 assert_equal true, c.http_get 192 193 assert_nil c.body_str194 assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)195 end 196 def test_get_03197 c = Curl::Easy.new($TEST_URL + "nonexistent") 198 assert_raise(Curl::Err::CouldntReadError) { c.http_get }199 assert_equal "", c.body_str200 assert_equal "", c.header_str201 end 202 def test_last_effective_url_01203 c = Curl::Easy.new($TEST_URL)204 205 assert_equal $TEST_URL, c.url206 assert_nil c.last_effective_url207 208 assert c.http_get209 210 assert_equal c.url, c.last_effective_url211 c.url = "file://some/new.url"212 213 assert_not_equal c.last_effective_url, c.url214 end215 def test_http_get_block216 curl = Curl::Easy.http_get(TestServlet.url) do|c|217 c.follow_location = true218 c.max_redirects = 3219 end220 assert_equal curl.url, curl.last_effective_url221 assert_equal 'GET', curl.body_str222 end223 224 def test_local_port_01225 c = Curl::Easy.new($TEST_URL)226 227 assert_nil c.local_port 228 assert_nil c.local_port_range229 assert_nil c.proxy_port230 231 c.local_port = 88232 assert_equal 88, c.local_port 233 assert_nil c.local_port_range234 assert_nil c.proxy_port235 236 c.local_port = nil237 assert_nil c.local_port 238 assert_nil c.local_port_range239 assert_nil c.proxy_port240 end241 242 def test_local_port_02243 c = Curl::Easy.new($TEST_URL)244 245 assert_nil c.local_port 246 assert_raise(ArgumentError) { c.local_port = 0 }247 assert_raise(ArgumentError) { c.local_port = 65536 }248 assert_raise(ArgumentError) { c.local_port = -1 }249 end250 251 def test_local_port_range_01252 c = Curl::Easy.new($TEST_URL)253 254 assert_nil c.local_port_range255 assert_nil c.local_port256 assert_nil c.proxy_port257 c.local_port_range = 88258 assert_equal 88, c.local_port_range259 assert_nil c.local_port260 assert_nil c.proxy_port261 262 c.local_port_range = nil263 264 assert_nil c.local_port_range265 assert_nil c.local_port266 assert_nil c.proxy_port267 end268 269 def test_local_port_range_02270 c = Curl::Easy.new($TEST_URL)271 272 assert_nil c.local_port_range 273 assert_raise(ArgumentError) { c.local_port_range = 0 }274 assert_raise(ArgumentError) { c.local_port_range = 65536 }275 assert_raise(ArgumentError) { c.local_port_range = -1 }276 end277 278 def test_proxy_url_01279 c = Curl::Easy.new($TEST_URL)280 281 assert_equal $TEST_URL, c.url282 assert_nil c.proxy_url283 284 c.proxy_url = "http://some.proxy" 285 assert_equal $TEST_URL, c.url286 assert_equal "http://some.proxy", c.proxy_url287 288 c.proxy_url = nil289 assert_equal $TEST_URL, c.url290 assert_nil c.proxy_url291 end292 293 def test_proxy_port_01294 c = Curl::Easy.new($TEST_URL)295 296 assert_nil c.local_port297 assert_nil c.local_port_range 298 assert_nil c.proxy_port 299 300 c.proxy_port = 88301 assert_equal 88, c.proxy_port 302 assert_nil c.local_port303 assert_nil c.local_port_range304 305 c.proxy_port = nil306 assert_nil c.proxy_port 307 assert_nil c.local_port308 assert_nil c.local_port_range309 end310 311 def test_proxy_port_02312 c = Curl::Easy.new($TEST_URL)313 314 assert_nil c.proxy_port 315 assert_raise(ArgumentError) { c.proxy_port = 0 }316 assert_raise(ArgumentError) { c.proxy_port = 65536 }317 assert_raise(ArgumentError) { c.proxy_port = -1 }318 end319 320 def test_proxy_type_01321 c = Curl::Easy.new($TEST_URL)322 323 assert_nil c.proxy_type324 325 c.proxy_type = 3326 assert_equal 3, c.proxy_type327 328 c.proxy_type = nil329 assert_nil c.proxy_type330 end331 332 def test_http_auth_types_01333 c = Curl::Easy.new($TEST_URL)334 335 assert_nil c.http_auth_types336 337 c.http_auth_types = 3338 assert_equal 3, c.http_auth_types339 340 c.http_auth_types = nil341 assert_nil c.http_auth_types342 end343 344 def test_proxy_auth_types_01345 c = Curl::Easy.new($TEST_URL)346 347 assert_nil c.proxy_auth_types348 349 c.proxy_auth_types = 3350 assert_equal 3, c.proxy_auth_types351 352 c.proxy_auth_types = nil353 assert_nil c.proxy_auth_types354 end355 356 def test_max_redirects_01357 c = Curl::Easy.new($TEST_URL)358 359 assert_nil c.max_redirects360 361 c.max_redirects = 3362 assert_equal 3, c.max_redirects363 364 c.max_redirects = nil365 assert_nil c.max_redirects366 end367 def test_timeout_with_floats368 c = Curl::Easy.new($TEST_URL)369 c.timeout = 1.5370 assert_equal 1500, c.timeout_ms371 assert_equal 1.5, c.timeout372 end373 def test_timeout_with_negative374 c = Curl::Easy.new($TEST_URL)375 c.timeout = -1.5376 assert_equal 0, c.timeout377 assert_equal 0, c.timeout_ms378 c.timeout = -4.8379 assert_equal 0, c.timeout380 assert_equal 0, c.timeout_ms381 end382 def test_timeout_01383 c = Curl::Easy.new($TEST_URL)384 assert_equal 0, c.timeout385 c.timeout = 3386 assert_equal 3, c.timeout387 c.timeout = 0388 assert_equal 0, c.timeout389 end390 def test_timeout_ms_01391 c = Curl::Easy.new($TEST_URL)392 assert_equal 0, c.timeout_ms393 c.timeout_ms = 100394 assert_equal 100, c.timeout_ms395 c.timeout_ms = nil396 assert_equal 0, c.timeout_ms397 end398 def test_timeout_ms_with_floats399 c = Curl::Easy.new($TEST_URL)400 c.timeout_ms = 55.5401 assert_equal 55, c.timeout_ms402 assert_equal 0.055, c.timeout403 end404 def test_timeout_ms_with_negative405 c = Curl::Easy.new($TEST_URL)406 c.timeout_ms = -1.5407 assert_equal 0, c.timeout408 assert_equal 0, c.timeout_ms409 c.timeout_ms = -4.8410 assert_equal 0, c.timeout411 assert_equal 0, c.timeout_ms412 end413 def test_connect_timeout_01414 c = Curl::Easy.new($TEST_URL)415 416 assert_nil c.connect_timeout417 418 c.connect_timeout = 3419 assert_equal 3, c.connect_timeout420 421 c.connect_timeout = nil422 assert_nil c.connect_timeout423 end424 def test_connect_timeout_ms_01425 c = Curl::Easy.new($TEST_URL)426 assert_nil c.connect_timeout_ms427 c.connect_timeout_ms = 100428 assert_equal 100, c.connect_timeout_ms429 c.connect_timeout_ms = nil430 assert_nil c.connect_timeout_ms431 end432 def test_ftp_response_timeout_01433 c = Curl::Easy.new($TEST_URL)434 435 assert_nil c.ftp_response_timeout436 437 c.ftp_response_timeout = 3438 assert_equal 3, c.ftp_response_timeout439 440 c.ftp_response_timeout = nil441 assert_nil c.ftp_response_timeout442 end443 444 def test_dns_cache_timeout_01445 c = Curl::Easy.new($TEST_URL)446 447 assert_equal 60, c.dns_cache_timeout448 449 c.dns_cache_timeout = nil450 assert_nil c.dns_cache_timeout451 452 c.dns_cache_timeout = 30453 assert_equal 30, c.dns_cache_timeout454 end455 456 def test_low_speed_limit_01457 c = Curl::Easy.new($TEST_URL)458 459 assert_nil c.low_speed_limit460 461 c.low_speed_limit = 3462 assert_equal 3, c.low_speed_limit463 464 c.low_speed_limit = nil465 assert_nil c.low_speed_limit466 end467 468 def test_low_speed_time_01469 c = Curl::Easy.new($TEST_URL)470 471 assert_nil c.low_speed_time472 473 c.low_speed_time = 3474 assert_equal 3, c.low_speed_time475 476 c.low_speed_time = nil477 assert_nil c.low_speed_time478 end479 480 def test_on_body481 blk = lambda { |i| i.length }482 483 c = Curl::Easy.new 484 c.on_body(&blk)485 486 assert_equal blk, c.on_body # sets handler nil, returns old handler487 assert_equal nil, c.on_body488 end489 def test_inspect_with_no_url490 c = Curl::Easy.new491 assert_equal '#<Curl::Easy>', c.inspect492 end493 494 def test_inspect_with_short_url495 c = Curl::Easy.new('http://www.google.com/')496 assert_equal "#<Curl::Easy http://www.google.com/>", c.inspect497 end498 499 def test_inspect_truncates_to_64_chars500 base_url = 'http://www.google.com/'501 truncated_url = base_url + 'x' * (64 - '#<Curl::Easy >'.size - base_url.size)502 long_url = truncated_url + 'yyyy'503 c = Curl::Easy.new(long_url)504 assert_equal 64, c.inspect.size505 assert_equal "#<Curl::Easy #{truncated_url}>", c.inspect506 end507 508 def test_on_header509 blk = lambda { |i| i.length }510 511 c = Curl::Easy.new 512 c.on_header(&blk)513 514 assert_equal blk, c.on_header # sets handler nil, returns old handler515 assert_equal nil, c.on_header516 end517 518 def test_on_progress519 blk = lambda { |*args| true }520 521 c = Curl::Easy.new 522 c.on_progress(&blk)523 524 assert_equal blk, c.on_progress # sets handler nil, returns old handler525 assert_equal nil, c.on_progress526 end527 528 def test_on_debug529 blk = lambda { |*args| true }530 531 c = Curl::Easy.new 532 c.on_debug(&blk)533 534 assert_equal blk, c.on_debug # sets handler nil, returns old handler535 assert_equal nil, c.on_debug536 end537 538 def test_proxy_tunnel539 c = Curl::Easy.new 540 assert !c.proxy_tunnel?541 assert c.proxy_tunnel = true542 assert c.proxy_tunnel?543 end544 545 def test_fetch_file_time546 c = Curl::Easy.new 547 assert !c.fetch_file_time?548 assert c.fetch_file_time = true549 assert c.fetch_file_time?550 end551 552 def test_ssl_verify_peer553 c = Curl::Easy.new 554 assert c.ssl_verify_peer?555 assert !c.ssl_verify_peer = false556 assert !c.ssl_verify_peer?557 end558 559 def test_ssl_verify_host560 c = Curl::Easy.new 561 assert c.ssl_verify_host?562 c.ssl_verify_host = 0563 c.ssl_verify_host = false564 assert !c.ssl_verify_host?565 end566 567 def test_header_in_body568 c = Curl::Easy.new 569 assert !c.header_in_body?570 assert c.header_in_body = true571 assert c.header_in_body?572 end573 574 def test_use_netrc575 c = Curl::Easy.new 576 assert !c.use_netrc?577 assert c.use_netrc = true578 assert c.use_netrc?579 end580 581 def test_follow_location582 c = Curl::Easy.new 583 assert !c.follow_location?584 assert c.follow_location = true585 assert c.follow_location?586 end587 588 def test_unrestricted_auth589 c = Curl::Easy.new 590 assert !c.unrestricted_auth?591 assert c.unrestricted_auth = true592 assert c.unrestricted_auth?593 end 594 595 def test_multipart_form_post596 c = Curl::Easy.new597 assert !c.multipart_form_post?598 assert c.multipart_form_post = true599 assert c.multipart_form_post?600 end601 def test_ignore_content_length602 c = Curl::Easy.new603 assert !c.ignore_content_length?604 assert c.ignore_content_length = true605 assert c.ignore_content_length?606 end607 def test_resolve_mode608 c = Curl::Easy.new609 assert_equal :auto, c.resolve_mode610 c.resolve_mode = :ipv4611 assert_equal :ipv4, c.resolve_mode 612 c.resolve_mode = :ipv6613 assert_equal :ipv6, c.resolve_mode 614 assert_raises(ArgumentError) { c.resolve_mode = :bad }615 end616 def test_enable_cookies617 c = Curl::Easy.new618 assert !c.enable_cookies?619 assert c.enable_cookies = true620 assert c.enable_cookies?621 end622 def test_cookies_option623 c = Curl::Easy.new624 assert_nil c.cookies625 assert_equal "name1=content1; name2=content2;", c.cookies = "name1=content1; name2=content2;"626 assert_equal "name1=content1; name2=content2;", c.cookies627 end628 def test_cookiefile629 c = Curl::Easy.new630 assert_nil c.cookiefile631 assert_equal "some.file", c.cookiefile = "some.file"632 assert_equal "some.file", c.cookiefile 633 end634 def test_cookiejar635 c = Curl::Easy.new636 assert_nil c.cookiejar637 assert_equal "some.file", c.cookiejar = "some.file"638 assert_equal "some.file", c.cookiejar 639 end640 def test_cookielist641 c = Curl::Easy.new TestServlet.url642 c.enable_cookies = true643 c.post_body = URI.encode_www_form('c' => 'somename=somevalue')644 assert_nil c.cookielist645 c.perform646 assert_match(/somevalue/, c.cookielist.join(''))647 end648 def test_on_success649 curl = Curl::Easy.new($TEST_URL) 650 on_success_called = false651 curl.on_success {|c|652 on_success_called = true653 assert_not_nil c.body_str654 assert_equal "", c.header_str655 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)656 }657 curl.perform658 assert on_success_called, "Success handler not called" 659 end660 def test_on_success_with_on_failure661 curl = Curl::Easy.new(TestServlet.url + '/error')662 on_failure_called = false663 curl.on_success {|c| } # make sure we get the failure call even though this handler is defined664 curl.on_failure {|c,code| on_failure_called = true }665 curl.perform666 assert_equal 500, curl.response_code667 assert on_failure_called, "Failure handler not called" 668 end669 def test_on_success_with_on_missing670 curl = Curl::Easy.new(TestServlet.url + '/not_here')671 on_missing_called = false672 curl.on_success {|c| } # make sure we get the missing call even though this handler is defined673 curl.on_missing {|c,code| on_missing_called = true }674 curl.perform675 assert_equal 404, curl.response_code676 assert on_missing_called, "Missing handler not called" 677 end678 def test_on_success_with_on_redirect679 curl = Curl::Easy.new(TestServlet.url + '/redirect')680 on_redirect_called = false681 curl.on_success {|c| } # make sure we get the redirect call even though this handler is defined682 curl.on_redirect {|c,code| on_redirect_called = true }683 curl.perform684 assert_equal 302, curl.response_code685 assert on_redirect_called, "Redirect handler not called" 686 end687 688 def test_get_remote689 curl = Curl::Easy.new(TestServlet.url)690 curl.http_get691 assert_equal 'GET', curl.body_str692 end693 694 def test_post_remote695 curl = Curl::Easy.new(TestServlet.url)696 curl.http_post([Curl::PostField.content('document_id', 5)])697 assert_equal "POST\ndocument_id=5", curl.unescape(curl.body_str)698 end699 def test_post_remote_is_easy_handle700 # see: http://pastie.org/560852 and701 # http://groups.google.com/group/curb---ruby-libcurl-bindings/browse_thread/thread/216bb2d9b037f347?hl=en702 [:post, :get, :head, :delete].each do |method|703 retries = 0704 begin705 count = 0706 Curl::Easy.send("http_#{method}", TestServlet.url) do|c|707 count += 1708 assert_equal Curl::Easy, c.class709 end710 assert_equal 1, count, "For request method: #{method.to_s.upcase}"711 rescue Curl::Err::HostResolutionError => e # travis-ci.org fails to resolve... try again?712 retries+=1713 retry if retries < 3714 raise e715 end716 end717 end718 # see: https://github.com/rvanlieshout/curb/commit/8bcdefddc0162484681ebd1a92d52a642666a445719 def test_post_multipart_array_remote720 curl = Curl::Easy.new(TestServlet.url)721 curl.multipart_form_post = true722 fields = [723 Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))),724 Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))725 ]726 curl.http_post(fields)727 assert_match(/HTTP POST file upload/, curl.body_str)728 assert_match(/Content-Disposition: form-data/, curl.body_str)729 end730 731 def test_post_with_body_remote732 curl = Curl::Easy.new(TestServlet.url)733 curl.post_body = 'foo=bar&encoded%20string=val'734 735 curl.perform736 737 assert_equal "POST\nfoo=bar&encoded%20string=val", curl.body_str738 assert_equal 'foo=bar&encoded%20string=val', curl.post_body739 end740 741 def test_form_post_body_remote742 curl = Curl::Easy.new(TestServlet.url)743 curl.http_post('foo=bar', 'encoded%20string=val')744 745 assert_equal "POST\nfoo=bar&encoded%20string=val", curl.body_str746 assert_equal 'foo=bar&encoded%20string=val', curl.post_body747 end748 def test_post_multipart_file_remote749 curl = Curl::Easy.new(TestServlet.url)750 curl.multipart_form_post = true751 pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))752 curl.http_post(pf)753 assert_match(/HTTP POST file upload/, curl.body_str)754 assert_match(/Content-Disposition: form-data/, curl.body_str)755 end756 def test_delete_remote757 curl = Curl::Easy.new(TestServlet.url)758 curl.http_delete759 assert_equal 'DELETE', curl.body_str760 end761 def test_arbitrary_http_verb762 curl = Curl::Easy.new(TestServlet.url)763 curl.http('PURGE')764 assert_equal 'PURGE', curl.body_str765 end766 def test_head_remote767 curl = Curl::Easy.new(TestServlet.url)768 curl.http_head769 redirect = curl.header_str.match(/Location: (.*)/)770 assert_equal '', curl.body_str771 assert_match('/nonexistent', redirect[1])772 end773 def test_head_accessor774 curl = Curl::Easy.new(TestServlet.url)775 curl.head = true776 curl.perform777 redirect = curl.header_str.match(/Location: (.*)/)778 assert_equal '', curl.body_str779 assert_match('/nonexistent', redirect[1])780 curl.head = false781 curl.perform782 assert_equal 'GET', curl.body_str783 end784 def test_put_remote785 curl = Curl::Easy.new(TestServlet.url)786 curl.headers['Content-Type'] = 'application/json'787 assert curl.http_put("message")788 assert_match(/^PUT/, curl.body_str)789 assert_match(/message$/, curl.body_str)790 assert_match(/message$/, curl.body)791 assert_match(/application\/json/, curl.header_str)792 assert_match(/application\/json/, curl.head)793 end 794 795 def test_put_data796 curl = Curl::Easy.new(TestServlet.url)797 curl.put_data = 'message'798 799 curl.perform800 801 assert_match(/^PUT/, curl.body_str)802 assert_match(/message$/, curl.body_str)803 end804 # https://github.com/taf2/curb/issues/101805 def test_put_data_null_bytes806 curl = Curl::Easy.new(TestServlet.url)807 curl.put_data = "a\0b"808 809 curl.perform810 811 assert_match(/^PUT/, curl.body_str)812 assert_match("a\0b", curl.body_str)813 end814 def test_put_nil_data_no_crash815 curl = Curl::Easy.new(TestServlet.url)816 curl.put_data = nil817 818 curl.perform819 end820 def test_put_remote_file821 curl = Curl::Easy.new(TestServlet.url)822 File.open(__FILE__,'rb') do|f|823 assert curl.http_put(f)824 end825 assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')826 end827 828 def test_put_class_method829 count = 0830 curl = Curl::Easy.http_put(TestServlet.url,File.open(__FILE__,'rb')) do|c|831 count += 1832 assert_equal Curl::Easy, c.class833 end834 assert_equal 1, count835 assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')836 end837 # Generate a self-signed cert with838 # openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 \839 # -keyout tests/cert.pem -out tests/cert.pem840 def test_cert841 curl = Curl::Easy.new(TestServlet.url)842 curl.cert= File.join(File.dirname(__FILE__),"cert.pem")843 assert_match(/cert.pem$/,curl.cert)844 end845 def test_cert_with_password846 curl = Curl::Easy.new(TestServlet.url)847 path = File.join(File.dirname(__FILE__),"cert.pem")848 curl.certpassword = 'password'849 curl.cert = path850 assert_match(/cert.pem$/,curl.cert)851 end852 def test_cert_type853 curl = Curl::Easy.new(TestServlet.url)854 curl.certtype= "DER"855 assert_equal "DER", curl.certtype856 end857 def test_default_certtype858 curl = Curl::Easy.new(TestServlet.url)859 assert_nil curl.certtype860 curl.certtype = "PEM"861 assert_equal "PEM", curl.certtype862 end863 # Generate a CA cert with instructions at864 # http://technocage.com/~caskey/openssl/865 def test_ca_cert866 curl = Curl::Easy.new(TestServlet.url)867 curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")868 assert_match(/cacert.pem$/, curl.cacert)869 end870 def test_user_agent871 curl = Curl::Easy.new(TestServlet.url)872 curl.useragent= "Curb-Easy/Ruby"873 assert_equal "Curb-Easy/Ruby",curl.useragent874 end875 def test_username_password876 curl = Curl::Easy.new(TestServlet.url)877 curl.username = "foo"878 curl.password = "bar"879 if !curl.username.nil?880 assert_equal "foo", curl.username881 assert_equal "bar", curl.password882 else883 curl.userpwd = "foo:bar"884 end885 curl.http_auth_types = :basic886 #curl.verbose = true887 curl.perform888 assert_equal 'Basic Zm9vOmJhcg==', $auth_header889 $auth_header = nil890 # curl checks the auth type supported by the server, so we have to create a 891 # new easy handle if we're going to change the auth type...892 curl = Curl::Easy.new(TestServlet.url)893 curl.username = "foo"894 curl.password = "bar"895 if curl.username.nil?896 curl.userpwd = "foo:bar"897 end898 curl.http_auth_types = :ntlm899 curl.perform900 assert_equal 'NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=', $auth_header901 end902 def test_primary_ip903 curl = Curl::Easy.new(TestServlet.url)904 if curl.respond_to?(:primary_ip)905 curl.perform906 assert_equal '127.0.0.1', curl.primary_ip907 end908 end909 def test_post_streaming910 readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))911 912 pf = Curl::PostField.file("filename", readme)913 easy = Curl::Easy.new914 easy.url = TestServlet.url915 easy.multipart_form_post = true916 easy.http_post(pf)917 assert_not_equal(0,easy.body_str.size)918 assert_equal(easy.body_str.tr("\r", ''), File.read(readme))919 end920 def test_easy_close921 easy = Curl::Easy.new922 easy.close923 easy.url = TestServlet.url924 easy.http_get925 end926 def test_easy_reset927 easy = Curl::Easy.new928 easy.url = TestServlet.url + "?query=foo"929 easy.http_get930 settings = easy.reset931 assert settings.key?(:url)932 assert settings.key?(:body_data)933 assert settings.key?(:header_data)934 easy.url = TestServlet.url935 easy.http_get936 end937 def test_easy_use_http_versions938 easy = Curl::Easy.new939 easy.url = TestServlet.url + "?query=foo"940 #puts "http none: #{Curl::HTTP_NONE.inspect}"941 #puts "http1.0: #{Curl::HTTP_1_0.inspect}"942 #puts "http1.1: #{Curl::HTTP_1_1.inspect}"943 easy.version = Curl::HTTP_1_1944 #easy.verbose = true945 easy.http_get946 end947 def test_easy_http_verbs948 curl = Curl::Easy.new(TestServlet.url)949 curl.http_delete950 assert_equal 'DELETE', curl.body_str951 curl.http_get952 assert_equal 'GET', curl.body_str953 curl.http_post954 assert_equal "POST\n", curl.body_str955 curl.http('PURGE')956 assert_equal 'PURGE', curl.body_str957 curl.http_put('hello')958 assert_equal "PUT\nhello", curl.body_str959 curl.http('COPY')960 assert_equal 'COPY', curl.body_str961 end962 def test_easy_http_verbs_must_respond_to_str963 # issue http://github.com/taf2/curb/issues#issue/45964 assert_nothing_raised do965 c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(:get)966 end967 assert_raise RuntimeError do968 c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(FooNoToS.new)969 end970 end971 # http://github.com/taf2/curb/issues/#issue/33972 def test_easy_http_verbs_with_errors973 curl = Curl::Easy.new("http://127.0.0.1:9012/") # test will fail if http server on port 9012974 assert_raise Curl::Err::ConnectionFailedError do975 curl.http_delete976 end977 curl.url = TestServlet.url978 curl.http_get979 assert_equal 'GET', curl.body_str980 end981 def test_easy_can_put_with_content_length982 curl = Curl::Easy.new(TestServlet.url)983 rd, wr = IO.pipe984 buf = (("hello")* (1000 / 5))985 producer = Thread.new do986 5.times do987 wr << buf988 sleep 0.1 # act as a slow producer989 end990 end991 consumer = Thread.new do992 #curl.verbose = true993 curl.headers['Content-Length'] = buf.size * 5994 curl.headers['User-Agent'] = "Something else"995 curl.headers['Content-Type'] = "text/javascript"996 curl.headers['Date'] = Time.now.httpdate997 curl.headers['Host'] = 's3.amazonaws.com'998 curl.headers['Accept'] = '*/*'999 curl.headers['Authorization'] = 'Foo Bar Biz Baz'1000 curl.http_put(rd)1001 assert_match(/^PUT/, curl.body_str)1002 assert_match(/hello$/, curl.body_str)1003 curl.header_str1004 curl.body_str1005 end1006 producer.join1007 wr.close1008 consumer.join1009 end1010 def test_get_set_multi_on_easy1011 easy = Curl::Easy.new1012 assert_nil easy.multi1013 multi = Curl::Multi.new1014 easy.multi = multi1015 assert_not_nil easy.multi1016 assert_equal multi, easy.multi1017 end1018 def test_raise_on_progress1019 c = Curl::Easy.new($TEST_URL)1020 c.on_progress {|w,x,y,z| raise "error" }1021 c.perform1022 rescue => e1023 assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s1024 c.close1025 end1026 def test_raise_on_success1027 c = Curl::Easy.new($TEST_URL)1028 c.on_success {|x| raise "error" }1029 c.perform1030 rescue => e1031 assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s1032 c.close1033 end1034 def test_raise_on_debug1035 c = Curl::Easy.new($TEST_URL)1036 c.on_debug { raise "error" }1037 c.perform1038 assert true, "raise in on debug has no effect"1039 end1040 def test_status_codes1041 curl = Curl::Easy.new(TestServlet.url)1042 curl.perform1043 assert_equal '200 OK', curl.status1044 end1045 def test_close_in_on_callbacks1046 curl = Curl::Easy.new(TestServlet.url)1047 curl.on_body {|d| curl.close; d.size }1048 assert_raises RuntimeError do1049 curl.perform1050 end1051 end1052 def test_set_unsupported_options1053 curl = Curl::Easy.new1054 assert_raises TypeError do1055 curl.set(99999, 1)1056 end1057 end1058 include TestServerMethods 1059 def setup1060 server_setup1061 end1062end...

Full Screen

Full Screen

easy.rb

Source:easy.rb Github

copy

Full Screen

...49 Curl.const_get("CURLOPT_#{opt.to_s.upcase}")50 end51 #52 # call-seq:53 # easy.perform => true54 #55 # Transfer the currently configured URL using the options set for this56 # Curl::Easy instance. If this is an HTTP URL, it will be transferred via57 # the configured HTTP Verb.58 #59 def perform60 self.multi = Curl::Multi.new if self.multi.nil?61 self.multi.add self62 ret = self.multi.perform63 self.multi.remove self64 if Curl::Multi.autoclose65 self.multi.close66 self.multi = nil67 end68 if self.last_result != 0 && self.on_failure.nil?69 (err_class, err_summary) = Curl::Easy.error(self.last_result)70 err_detail = self.last_error71 raise err_class.new([err_summary, err_detail].compact.join(": "))72 end73 ret74 end75 #76 # call-seq:77 #78 # easy = Curl::Easy.new79 # easy.nosignal = true80 #81 def nosignal=(onoff)82 set :nosignal, !!onoff83 end84 #85 # call-seq:86 # easy = Curl::Easy.new("url") do|c|87 # c.delete = true88 # end89 # easy.perform90 #91 def delete=(onoff)92 set :customrequest, onoff ? 'DELETE' : nil93 onoff94 end95 #96 # call-seq:97 #98 # easy = Curl::Easy.new("url")99 # easy.version = Curl::HTTP_2_0100 # easy.version = Curl::HTTP_1_1101 # easy.version = Curl::HTTP_1_0102 # easy.version = Curl::HTTP_NONE103 #104 def version=(http_version)105 set :http_version, http_version106 end107 #108 # call-seq:109 # easy.url = "http://some.url/" => "http://some.url/"110 #111 # Set the URL for subsequent calls to +perform+. It is acceptable112 # (and even recommended) to reuse Curl::Easy instances by reassigning113 # the URL between calls to +perform+.114 #115 def url=(u)116 set :url, u117 end118 #119 # call-seq:120 # easy.proxy_url = string => string121 #122 # Set the URL of the HTTP proxy to use for subsequent calls to +perform+.123 # The URL should specify the the host name or dotted IP address. To specify124 # port number in this string, append :[port] to the end of the host name.125 # The proxy string may be prefixed with [protocol]:// since any such prefix126 # will be ignored. The proxy's port number may optionally be specified with127 # the separate option proxy_port .128 #129 # When you tell the library to use an HTTP proxy, libcurl will transparently130 # convert operations to HTTP even if you specify an FTP URL etc. This may have131 # an impact on what other features of the library you can use, such as132 # FTP specifics that don't work unless you tunnel through the HTTP proxy. Such133 # tunneling is activated with proxy_tunnel = true.134 #135 # libcurl respects the environment variables *http_proxy*, *ftp_proxy*,136 # *all_proxy* etc, if any of those is set. The proxy_url option does however137 # override any possibly set environment variables.138 #139 # Starting with libcurl 7.14.1, the proxy host string given in environment140 # variables can be specified the exact same way as the proxy can be set with141 # proxy_url, including protocol prefix (http://) and embedded user + password.142 #143 def proxy_url=(url)144 set :proxy, url145 end146 def ssl_verify_host=(value)147 value = 1 if value.class == TrueClass148 value = 0 if value.class == FalseClass149 self.ssl_verify_host_integer=value150 end151 #152 # call-seq:153 # easy.ssl_verify_host? => boolean154 #155 # Deprecated: call easy.ssl_verify_host instead156 # can be one of [0,1,2]157 #158 # Determine whether this Curl instance will verify that the server cert159 # is for the server it is known as.160 #161 def ssl_verify_host?162 ssl_verify_host.nil? ? false : (ssl_verify_host > 0)163 end164 #165 # call-seq:166 # easy.interface = string => string167 #168 # Set the interface name to use as the outgoing network interface.169 # The name can be an interface name, an IP address or a host name.170 #171 def interface=(value)172 set :interface, value173 end174 #175 # call-seq:176 # easy.userpwd = string => string177 #178 # Set the username/password string to use for subsequent calls to +perform+.179 # The supplied string should have the form "username:password"180 #181 def userpwd=(value)182 set :userpwd, value183 end184 #185 # call-seq:186 # easy.proxypwd = string => string187 #188 # Set the username/password string to use for proxy connection during189 # subsequent calls to +perform+. The supplied string should have the190 # form "username:password"191 #192 def proxypwd=(value)193 set :proxyuserpwd, value194 end195 #196 # call-seq:197 # easy.cookies = "name1=content1; name2=content2;" => string198 #199 # Set cookies to be sent by this Curl::Easy instance. The format of the string should200 # be NAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie should contain.201 # Set multiple cookies in one string like this: "name1=content1; name2=content2;" etc.202 #203 def cookies=(value)204 set :cookie, value205 end206 #207 # call-seq:208 # easy.cookiefile = string => string209 #210 # Set a file that contains cookies to be sent in subsequent requests by this Curl::Easy instance.211 #212 # *Note* that you must set enable_cookies true to enable the cookie213 # engine, or this option will be ignored.214 #215 def cookiefile=(value)216 set :cookiefile, value217 end218 #219 # call-seq:220 # easy.cookiejar = string => string221 #222 # Set a cookiejar file to use for this Curl::Easy instance.223 # Cookies from the response will be written into this file.224 #225 # *Note* that you must set enable_cookies true to enable the cookie226 # engine, or this option will be ignored.227 #228 def cookiejar=(value)229 set :cookiejar, value230 end231 #232 # call-seq:233 # easy = Curl::Easy.new("url") do|c|234 # c.head = true235 # end236 # easy.perform237 #238 def head=(onoff)239 set :nobody, onoff240 end241 #242 # call-seq:243 # easy.follow_location = boolean => boolean244 #245 # Configure whether this Curl instance will follow Location: headers246 # in HTTP responses. Redirects will only be followed to the extent247 # specified by +max_redirects+.248 #249 def follow_location=(onoff)250 set :followlocation, onoff251 end252 #253 # call-seq:254 # easy.http_head => true255 #256 # Request headers from the currently configured URL using the HEAD257 # method and current options set for this Curl::Easy instance. This258 # method always returns true, or raises an exception (defined under259 # Curl::Err) on error.260 #261 def http_head262 set :nobody, true263 ret = self.perform264 set :nobody, false265 ret266 end267 #268 # call-seq:269 # easy.http_get => true270 #271 # GET the currently configured URL using the current options set for272 # this Curl::Easy instance. This method always returns true, or raises273 # an exception (defined under Curl::Err) on error.274 #275 def http_get276 set :httpget, true277 http :GET278 end279 alias get http_get280 #281 # call-seq:282 # easy.http_delete283 #284 # DELETE the currently configured URL using the current options set for285 # this Curl::Easy instance. This method always returns true, or raises286 # an exception (defined under Curl::Err) on error.287 #288 def http_delete289 self.http :DELETE290 end291 alias delete http_delete292 class << self293 #294 # call-seq:295 # Curl::Easy.perform(url) { |easy| ... } => #<Curl::Easy...>296 #297 # Convenience method that creates a new Curl::Easy instance with298 # the specified URL and calls the general +perform+ method, before returning299 # the new instance. For HTTP URLs, this is equivalent to calling +http_get+.300 #301 # If a block is supplied, the new instance will be yielded just prior to302 # the +http_get+ call.303 #304 def perform(*args)305 c = Curl::Easy.new(*args)306 yield c if block_given?307 c.perform308 c309 end310 #311 # call-seq:312 # Curl::Easy.http_get(url) { |easy| ... } => #<Curl::Easy...>313 #314 # Convenience method that creates a new Curl::Easy instance with315 # the specified URL and calls +http_get+, before returning the new instance.316 #317 # If a block is supplied, the new instance will be yielded just prior to318 # the +http_get+ call.319 #320 def http_get(*args)321 c = Curl::Easy.new(*args)322 yield c if block_given?323 c.http_get324 c325 end326 #327 # call-seq:328 # Curl::Easy.http_head(url) { |easy| ... } => #<Curl::Easy...>329 #330 # Convenience method that creates a new Curl::Easy instance with331 # the specified URL and calls +http_head+, before returning the new instance.332 #333 # If a block is supplied, the new instance will be yielded just prior to334 # the +http_head+ call.335 #336 def http_head(*args)337 c = Curl::Easy.new(*args)338 yield c if block_given?339 c.http_head340 c341 end342 #343 # call-seq:344 # Curl::Easy.http_put(url, data) {|c| ... }345 #346 # see easy.http_put347 #348 def http_put(url, data)349 c = Curl::Easy.new url350 yield c if block_given?351 c.http_put data352 c353 end354 #355 # call-seq:356 # Curl::Easy.http_post(url, "some=urlencoded%20form%20data&and=so%20on") => true357 # Curl::Easy.http_post(url, "some=urlencoded%20form%20data", "and=so%20on", ...) => true358 # Curl::Easy.http_post(url, "some=urlencoded%20form%20data", Curl::PostField, "and=so%20on", ...) => true359 # Curl::Easy.http_post(url, Curl::PostField, Curl::PostField ..., Curl::PostField) => true360 #361 # POST the specified formdata to the currently configured URL using362 # the current options set for this Curl::Easy instance. This method363 # always returns true, or raises an exception (defined under364 # Curl::Err) on error.365 #366 # If you wish to use multipart form encoding, you'll need to supply a block367 # in order to set multipart_form_post true. See #http_post for more368 # information.369 #370 def http_post(*args)371 url = args.shift372 c = Curl::Easy.new url373 yield c if block_given?374 c.http_post(*args)375 c376 end377 #378 # call-seq:379 # Curl::Easy.http_delete(url) { |easy| ... } => #<Curl::Easy...>380 #381 # Convenience method that creates a new Curl::Easy instance with382 # the specified URL and calls +http_delete+, before returning the new instance.383 #384 # If a block is supplied, the new instance will be yielded just prior to385 # the +http_delete+ call.386 #387 def http_delete(*args)388 c = Curl::Easy.new(*args)389 yield c if block_given?390 c.http_delete391 c392 end393 # call-seq:394 # Curl::Easy.download(url, filename = url.split(/\?/).first.split(/\//).last) { |curl| ... }395 #396 # Stream the specified url (via perform) and save the data directly to the397 # supplied filename (defaults to the last component of the URL path, which will398 # usually be the filename most simple urls).399 #400 # If a block is supplied, it will be passed the curl instance prior to the401 # perform call.402 #403 # *Note* that the semantics of the on_body handler are subtly changed when using404 # download, to account for the automatic routing of data to the specified file: The405 # data string is passed to the handler *before* it is written406 # to the file, allowing the handler to perform mutative operations where407 # necessary. As usual, the transfer will be aborted if the on_body handler408 # returns a size that differs from the data chunk size - in this case, the409 # offending chunk will *not* be written to the file, the file will be closed,410 # and a Curl::Err::AbortedByCallbackError will be raised.411 def download(url, filename = url.split(/\?/).first.split(/\//).last, &blk)412 curl = Curl::Easy.new(url, &blk)413 output = if filename.is_a? IO414 filename.binmode if filename.respond_to?(:binmode)415 filename416 else417 File.open(filename, 'wb')418 end419 begin420 old_on_body = curl.on_body do |data|421 result = old_on_body ? old_on_body.call(data) : data.length422 output << data if result == data.length423 result424 end425 curl.perform426 ensure427 output.close rescue IOError428 end429 return curl430 end431 end432 # Allow the incoming cert string to be file:password433 # but be careful to not use a colon from a windows file path434 # as the split point. Mimic what curl's main does435 if respond_to?(:cert=)436 alias_method :native_cert=, :cert=437 def cert=(cert_file)438 pos = cert_file.rindex(':')439 if pos && pos > 1...

Full Screen

Full Screen

multi.rb

Source:multi.rb Github

copy

Full Screen

...21 def add(easy)22 raise "trying to add easy handle twice" if @easy_handles.include?(easy)23 easy.set_headers() if easy.headers.empty?24 code = Curl.multi_add_handle(@handle, easy.handle)25 raise RuntimeError.new("An error occured adding the handle: #{code}: #{Curl.multi_strerror(code)}") if code != :call_multi_perform and code != :ok26 do_perform if code == :call_multi_perform27 @active += 128 @easy_handles << easy29 easy30 end31 def remove(easy)32 if @easy_handles.include?(easy)33 @active -= 134 Curl.multi_remove_handle(@handle, easy.handle)35 @easy_handles.delete(easy)36 end37 end38 def perform39 while @active > 040 run41 while @running > 042 # get the curl-suggested timeout43 code = Curl.multi_timeout(@handle, @timeout)44 raise RuntimeError.new("an error occured getting the timeout: #{code}: #{Curl.multi_strerror(code)}") if code != :ok45 timeout = @timeout.read_long46 if timeout == 0 # no delay47 run48 next49 elsif timeout < 050 timeout = 151 end52 # load the fd sets from the multi handle53 @fd_read.clear54 @fd_write.clear55 @fd_excep.clear56 code = Curl.multi_fdset(@handle, @fd_read, @fd_write, @fd_excep, @max_fd)57 raise RuntimeError.new("an error occured getting the fdset: #{code}: #{Curl.multi_strerror(code)}") if code != :ok58 max_fd = @max_fd.read_int59 if max_fd == -160 # curl is doing something special so let it run for a moment61 sleep(0.001)62 else63 @timeval[:sec] = timeout / 100064 @timeval[:usec] = (timeout * 1000) % 100000065 code = Curl.select(max_fd + 1, @fd_read, @fd_write, @fd_excep, @timeval)66 raise RuntimeError.new("error on thread select: #{::FFI.errno}") if code < 067 end68 run69 end70 end71 reset_easy_handles72 end73 def fire_and_forget74 run75 end76 # check for finished easy handles and remove from the multi handle77 def read_info78 msgs_left = ::FFI::MemoryPointer.new(:int)79 while not (msg = Curl.multi_info_read(@handle, msgs_left)).null?80 next if msg[:code] != :done81 easy = @easy_handles.find {|easy| easy.handle == msg[:easy_handle] }82 next if not easy83 response_code = ::FFI::MemoryPointer.new(:long)84 response_code.write_long(-1)85 Curl.easy_getinfo(easy.handle, :response_code, response_code)86 response_code = response_code.read_long87 remove(easy)88 easy.curl_return_code = msg[:data][:code]89 if easy.curl_return_code != 0 then easy.failure90 elsif (200..299).member?(response_code) or response_code == 0 then easy.success91 else easy.failure92 end93 end94 end95 def cleanup96 Curl.multi_cleanup(@handle)97 @active = 098 @running = 099 @easy_handles = []100 end101 def reset_easy_handles102 @easy_handles.dup.each do |easy|103 remove(easy)104 yield easy if block_given?105 end106 end107 private108 # called by perform and fire_and_forget109 def run110 begin code = do_perform end while code == :call_multi_perform111 raise RuntimeError.new("an error occured while running perform: #{code}: #{Curl.multi_strerror(code)}") if code != :ok112 read_info113 end114 def do_perform115 running = ::FFI::MemoryPointer.new(:int)116 code = Curl.multi_perform(@handle, running)117 @running = running.read_int118 code119 end120 end121end...

Full Screen

Full Screen

perform

Using AI Code Generation

copy

Full Screen

1 def initialize(url)2 uri = URI.parse(@url)3 response = Net::HTTP.get_response(uri)4curl = Curl.new(url)5curl = Curl.new(url)6curl = Curl.new(url)7curl = Curl.new(url)8curl = Curl.new(url)9curl = Curl.new(url)10curl = Curl.new(url)11curl = Curl.new(url)12curl = Curl.new(url)

Full Screen

Full Screen

perform

Using AI Code Generation

copy

Full Screen

1 def initialize(url)2 uri = URI.parse(@url)3 response = Net::HTTP.get_response(uri)4curl = Curl.new(url)5curl = Curl.new(url)6curl = Curl.new(url)7curl = Curl.new(url)8curl = Curl.new(url)9curl = Curl.new(url)10curl = Curl.new(url)11curl = Curl.new(url)12curl = Curl.new(url)

Full Screen

Full Screen

perform

Using AI Code Generation

copy

Full Screen

1 def initialize(url)2 uri = URI.parse(@url)3 response = Net::HTTP.get_response(uri)4curl = Curl.new(url)5curl = Curl.new(url)6curl = Curl.new(url)7curl = Curl.new(url)8curl = Curl.new(url)9curl = Curl.new(url)10curl = Curl.new(url)11curl = Curl.new(url)12curl = Curl.new(url)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful