How to use body_str method of Curl Package

Best Webmock_ruby code snippet using Curl.body_str

tc_curl_easy.rb

Source:tc_curl_easy.rb Github

copy

Full Screen

...4end5class TestCurbCurlEasy < Test::Unit::TestCase6 def test_class_perform_01 7 assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)8 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)9 assert_equal "", c.header_str10 end 11 def test_class_perform_0212 data = ""13 assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } } 14 assert_nil c.body_str15 assert_equal "", c.header_str16 assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)17 end 18 def test_class_perform_0319 assert_raise(Curl::Err::CouldntReadError) { c = Curl::Easy.perform($TEST_URL + "nonexistent") }20 end 21 22 def test_new_0123 c = Curl::Easy.new24 assert_equal Curl::Easy, c.class25 assert_nil c.url26 assert_nil c.body_str27 assert_nil c.header_str28 end29 def test_new_0230 c = Curl::Easy.new($TEST_URL)31 assert_equal $TEST_URL, c.url32 end33 34 def test_new_0335 blk = lambda { |i| i.length }36 37 c = Curl::Easy.new do |curl|38 curl.on_body(&blk)39 end40 41 assert_nil c.url 42 assert_equal blk, c.on_body # sets handler nil, returns old handler43 assert_equal nil, c.on_body44 end45 46 def test_new_0447 blk = lambda { |i| i.length }48 49 c = Curl::Easy.new($TEST_URL) do |curl|50 curl.on_body(&blk)51 end52 53 assert_equal $TEST_URL, c.url54 assert_equal blk, c.on_body # sets handler nil, returns old handler55 assert_equal nil, c.on_body56 end57 class Foo < Curl::Easy ; end58 def test_new_0559 # can use Curl::Easy as a base class60 c = Foo.new61 assert_equal Foo, c.class62 c.url = $TEST_URL63 c.perform64 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)65 end66 # test invalid use of new67 def test_new_0668 Curl::Easy.new(TestServlet.url) do|curl|69 curl.http_post70 assert_equal "POST\n", curl.body_str71 end72 end73 def test_escape74 c = Curl::Easy.new75 76 assert_equal "one%20two", c.escape('one two')77 assert_equal "one%00two%20three", c.escape("one\000two three") 78 end79 80 def test_unescape81 c = Curl::Easy.new82 83 assert_equal "one two", c.unescape('one%20two')84 85 # prior to 7.15.4 embedded nulls cannot be unescaped86 if Curl::VERNUM >= 0x070f0487 assert_equal "one\000two three", c.unescape("one%00two%20three")88 end89 end90 91 def test_headers92 c = Curl::Easy.new($TEST_URL)93 94 assert_equal({}, c.headers)95 c.headers = "Expect:"96 assert_equal "Expect:", c.headers97 c.headers = ["Expect:", "User-Agent: myapp-0.0.0"]98 assert_equal ["Expect:", "User-Agent: myapp-0.0.0"], c.headers99 end 100 def test_get_01 101 c = Curl::Easy.new($TEST_URL) 102 assert_equal true, c.http_get103 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)104 assert_equal "", c.header_str105 end 106 def test_get_02107 data = ""108 c = Curl::Easy.new($TEST_URL) do |curl|109 curl.on_body { |d| data << d; d.length }110 end111 112 assert_equal true, c.http_get 113 114 assert_nil c.body_str115 assert_equal "", c.header_str116 assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)117 end 118 def test_get_03119 c = Curl::Easy.new($TEST_URL + "nonexistent") 120 assert_raise(Curl::Err::CouldntReadError) { c.http_get }121 assert_equal "", c.body_str122 assert_equal "", c.header_str123 end 124 def test_last_effective_url_01125 c = Curl::Easy.new($TEST_URL)126 127 assert_equal $TEST_URL, c.url128 assert_nil c.last_effective_url129 130 assert c.http_get131 132 assert_equal c.url, c.last_effective_url133 c.url = "file://some/new.url"134 135 assert_not_equal c.last_effective_url, c.url136 end137 def test_http_get_block138 curl = Curl::Easy.http_get(TestServlet.url) do|c|139 c.follow_location = true140 c.max_redirects = 3141 end142 assert_equal curl.url, curl.last_effective_url143 assert_equal 'GET', curl.body_str144 end145 146 def test_local_port_01147 c = Curl::Easy.new($TEST_URL)148 149 assert_nil c.local_port 150 assert_nil c.local_port_range151 assert_nil c.proxy_port152 153 c.local_port = 88154 assert_equal 88, c.local_port 155 assert_nil c.local_port_range156 assert_nil c.proxy_port157 158 c.local_port = nil159 assert_nil c.local_port 160 assert_nil c.local_port_range161 assert_nil c.proxy_port162 end163 164 def test_local_port_02165 c = Curl::Easy.new($TEST_URL)166 167 assert_nil c.local_port 168 assert_raise(ArgumentError) { c.local_port = 0 }169 assert_raise(ArgumentError) { c.local_port = 65536 }170 assert_raise(ArgumentError) { c.local_port = -1 }171 end172 173 def test_local_port_range_01174 c = Curl::Easy.new($TEST_URL)175 176 assert_nil c.local_port_range177 assert_nil c.local_port178 assert_nil c.proxy_port179 c.local_port_range = 88180 assert_equal 88, c.local_port_range181 assert_nil c.local_port182 assert_nil c.proxy_port183 184 c.local_port_range = nil185 186 assert_nil c.local_port_range187 assert_nil c.local_port188 assert_nil c.proxy_port189 end190 191 def test_local_port_range_02192 c = Curl::Easy.new($TEST_URL)193 194 assert_nil c.local_port_range 195 assert_raise(ArgumentError) { c.local_port_range = 0 }196 assert_raise(ArgumentError) { c.local_port_range = 65536 }197 assert_raise(ArgumentError) { c.local_port_range = -1 }198 end199 200 def test_proxy_url_01201 c = Curl::Easy.new($TEST_URL)202 203 assert_equal $TEST_URL, c.url204 assert_nil c.proxy_url205 206 c.proxy_url = "http://some.proxy" 207 assert_equal $TEST_URL, c.url208 assert_equal "http://some.proxy", c.proxy_url209 210 c.proxy_url = nil211 assert_equal $TEST_URL, c.url212 assert_nil c.proxy_url213 end214 215 def test_proxy_port_01216 c = Curl::Easy.new($TEST_URL)217 218 assert_nil c.local_port219 assert_nil c.local_port_range 220 assert_nil c.proxy_port 221 222 c.proxy_port = 88223 assert_equal 88, c.proxy_port 224 assert_nil c.local_port225 assert_nil c.local_port_range226 227 c.proxy_port = nil228 assert_nil c.proxy_port 229 assert_nil c.local_port230 assert_nil c.local_port_range231 end232 233 def test_proxy_port_02234 c = Curl::Easy.new($TEST_URL)235 236 assert_nil c.proxy_port 237 assert_raise(ArgumentError) { c.proxy_port = 0 }238 assert_raise(ArgumentError) { c.proxy_port = 65536 }239 assert_raise(ArgumentError) { c.proxy_port = -1 }240 end241 242 def test_proxy_type_01243 c = Curl::Easy.new($TEST_URL)244 245 assert_nil c.proxy_type246 247 c.proxy_type = 3248 assert_equal 3, c.proxy_type249 250 c.proxy_type = nil251 assert_nil c.proxy_type252 end253 254 def test_http_auth_types_01255 c = Curl::Easy.new($TEST_URL)256 257 assert_nil c.http_auth_types258 259 c.http_auth_types = 3260 assert_equal 3, c.http_auth_types261 262 c.http_auth_types = nil263 assert_nil c.http_auth_types264 end265 266 def test_proxy_auth_types_01267 c = Curl::Easy.new($TEST_URL)268 269 assert_nil c.proxy_auth_types270 271 c.proxy_auth_types = 3272 assert_equal 3, c.proxy_auth_types273 274 c.proxy_auth_types = nil275 assert_nil c.proxy_auth_types276 end277 278 def test_max_redirects_01279 c = Curl::Easy.new($TEST_URL)280 281 assert_nil c.max_redirects282 283 c.max_redirects = 3284 assert_equal 3, c.max_redirects285 286 c.max_redirects = nil287 assert_nil c.max_redirects288 end289 290 def test_timeout_01291 c = Curl::Easy.new($TEST_URL)292 293 assert_nil c.timeout294 295 c.timeout = 3296 assert_equal 3, c.timeout297 298 c.timeout = nil299 assert_nil c.timeout300 end301 302 def test_connect_timeout_01303 c = Curl::Easy.new($TEST_URL)304 305 assert_nil c.connect_timeout306 307 c.connect_timeout = 3308 assert_equal 3, c.connect_timeout309 310 c.connect_timeout = nil311 assert_nil c.connect_timeout312 end313 314 def test_ftp_response_timeout_01315 c = Curl::Easy.new($TEST_URL)316 317 assert_nil c.ftp_response_timeout318 319 c.ftp_response_timeout = 3320 assert_equal 3, c.ftp_response_timeout321 322 c.ftp_response_timeout = nil323 assert_nil c.ftp_response_timeout324 end325 326 def test_dns_cache_timeout_01327 c = Curl::Easy.new($TEST_URL)328 329 assert_equal 60, c.dns_cache_timeout330 331 c.dns_cache_timeout = nil332 assert_nil c.dns_cache_timeout333 334 c.dns_cache_timeout = 30335 assert_equal 30, c.dns_cache_timeout336 end337 338 def test_low_speed_limit_01339 c = Curl::Easy.new($TEST_URL)340 341 assert_nil c.low_speed_limit342 343 c.low_speed_limit = 3344 assert_equal 3, c.low_speed_limit345 346 c.low_speed_limit = nil347 assert_nil c.low_speed_limit348 end349 350 def test_low_speed_time_01351 c = Curl::Easy.new($TEST_URL)352 353 assert_nil c.low_speed_time354 355 c.low_speed_time = 3356 assert_equal 3, c.low_speed_time357 358 c.low_speed_time = nil359 assert_nil c.low_speed_time360 end361 362 def test_on_body363 blk = lambda { |i| i.length }364 365 c = Curl::Easy.new 366 c.on_body(&blk)367 368 assert_equal blk, c.on_body # sets handler nil, returns old handler369 assert_equal nil, c.on_body370 end371 def test_inspect_with_no_url372 c = Curl::Easy.new373 assert_equal '#<Curl::Easy>', c.inspect374 end375 376 def test_inspect_with_short_url377 c = Curl::Easy.new('http://www.google.com/')378 assert_equal "#<Curl::Easy http://www.google.com/>", c.inspect379 end380 381 def test_inspect_truncates_to_64_chars382 base_url = 'http://www.google.com/'383 truncated_url = base_url + 'x' * (64 - '#<Curl::Easy >'.size - base_url.size)384 long_url = truncated_url + 'yyyy'385 c = Curl::Easy.new(long_url)386 assert_equal 64, c.inspect.size387 assert_equal "#<Curl::Easy #{truncated_url}>", c.inspect388 end389 390 def test_on_header391 blk = lambda { |i| i.length }392 393 c = Curl::Easy.new 394 c.on_header(&blk)395 396 assert_equal blk, c.on_header # sets handler nil, returns old handler397 assert_equal nil, c.on_header398 end399 400 def test_on_progress401 blk = lambda { |*args| true }402 403 c = Curl::Easy.new 404 c.on_progress(&blk)405 406 assert_equal blk, c.on_progress # sets handler nil, returns old handler407 assert_equal nil, c.on_progress408 end409 410 def test_on_debug411 blk = lambda { |*args| true }412 413 c = Curl::Easy.new 414 c.on_debug(&blk)415 416 assert_equal blk, c.on_debug # sets handler nil, returns old handler417 assert_equal nil, c.on_debug418 end419 420 def test_proxy_tunnel421 c = Curl::Easy.new 422 assert !c.proxy_tunnel?423 assert c.proxy_tunnel = true424 assert c.proxy_tunnel?425 end426 427 def test_fetch_file_time428 c = Curl::Easy.new 429 assert !c.fetch_file_time?430 assert c.fetch_file_time = true431 assert c.fetch_file_time?432 end433 434 def test_ssl_verify_peer435 c = Curl::Easy.new 436 assert c.ssl_verify_peer?437 assert !c.ssl_verify_peer = false438 assert !c.ssl_verify_peer?439 end440 441 def test_ssl_verify_host442 c = Curl::Easy.new 443 assert c.ssl_verify_host?444 assert !c.ssl_verify_host = false445 assert !c.ssl_verify_host?446 end447 448 def test_header_in_body449 c = Curl::Easy.new 450 assert !c.header_in_body?451 assert c.header_in_body = true452 assert c.header_in_body?453 end454 455 def test_use_netrc456 c = Curl::Easy.new 457 assert !c.use_netrc?458 assert c.use_netrc = true459 assert c.use_netrc?460 end461 462 def test_follow_location463 c = Curl::Easy.new 464 assert !c.follow_location?465 assert c.follow_location = true466 assert c.follow_location?467 end468 469 def test_unrestricted_auth470 c = Curl::Easy.new 471 assert !c.unrestricted_auth?472 assert c.unrestricted_auth = true473 assert c.unrestricted_auth?474 end 475 476 def test_multipart_form_post477 c = Curl::Easy.new478 assert !c.multipart_form_post?479 assert c.multipart_form_post = true480 assert c.multipart_form_post?481 end482 def test_ignore_content_length483 c = Curl::Easy.new484 assert !c.ignore_content_length?485 assert c.ignore_content_length = true486 assert c.ignore_content_length?487 end488 def test_enable_cookies489 c = Curl::Easy.new490 assert !c.enable_cookies?491 assert c.enable_cookies = true492 assert c.enable_cookies?493 end494 def test_cookies_option495 c = Curl::Easy.new496 assert_nil c.cookies497 assert_equal "name1=content1; name2=content2;", c.cookies = "name1=content1; name2=content2;"498 assert_equal "name1=content1; name2=content2;", c.cookies499 end500 def test_cookiefile501 c = Curl::Easy.new502 assert_nil c.cookiefile503 assert_equal "some.file", c.cookiefile = "some.file"504 assert_equal "some.file", c.cookiefile 505 end506 def test_cookiejar507 c = Curl::Easy.new508 assert_nil c.cookiejar509 assert_equal "some.file", c.cookiejar = "some.file"510 assert_equal "some.file", c.cookiejar 511 end512 def test_on_success513 curl = Curl::Easy.new($TEST_URL) 514 on_success_called = false515 curl.on_success {|c|516 on_success_called = true517 assert_not_nil c.body_str518 assert_equal "", c.header_str519 assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)520 }521 curl.perform522 assert on_success_called, "Success handler not called" 523 end524 def test_on_success_with_on_failure525 curl = Curl::Easy.new("#{$TEST_URL.gsub(/file:\/\//,'')}/not_here")526 on_failure_called = false527 curl.on_success {|c| } # make sure we get the failure call even though this handler is defined528 curl.on_failure {|c,code| on_failure_called = true }529 curl.perform530 assert on_failure_called, "Failure handler not called" 531 end532 533 def test_get_remote534 curl = Curl::Easy.new(TestServlet.url)535 curl.http_get536 assert_equal 'GET', curl.body_str537 end538 539 def test_post_remote540 curl = Curl::Easy.new(TestServlet.url)541 curl.http_post([Curl::PostField.content('document_id', 5)])542 assert_equal "POST\ndocument_id=5", curl.unescape(curl.body_str)543 end544 def test_post_remote_is_easy_handle545 # see: http://pastie.org/560852 and546 # http://groups.google.com/group/curb---ruby-libcurl-bindings/browse_thread/thread/216bb2d9b037f347?hl=en547 [:post, :get,:head,:delete].each do |method|548 count = 0549 curl = Curl::Easy.send("http_#{method}", TestServlet.url) do|c|550 count += 1551 assert_equal Curl::Easy, c.class552 end553 assert_equal 1, count, "For request method: #{method.to_s.upcase}"554 end555 end556 557 def test_post_with_body_remote558 curl = Curl::Easy.new(TestServlet.url)559 curl.post_body = 'foo=bar&encoded%20string=val'560 561 curl.perform562 563 assert_equal "POST\nfoo=bar&encoded%20string=val", curl.body_str564 assert_equal 'foo=bar&encoded%20string=val', curl.post_body565 end566 567 def test_form_post_body_remote568 curl = Curl::Easy.new(TestServlet.url)569 curl.http_post('foo=bar', 'encoded%20string=val')570 571 assert_equal "POST\nfoo=bar&encoded%20string=val", curl.body_str572 assert_equal 'foo=bar&encoded%20string=val', curl.post_body573 end574 def test_post_multipart_file_remote575 curl = Curl::Easy.new(TestServlet.url)576 curl.multipart_form_post = true577 pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))578 curl.http_post(pf)579 assert_match /HTTP POST file upload/, curl.body_str580 assert_match /Content-Disposition: form-data/, curl.body_str581 end582 def test_delete_remote583 curl = Curl::Easy.new(TestServlet.url)584 curl.http_delete585 assert_equal 'DELETE', curl.body_str586 end587 def test_arbitrary_http_verb588 curl = Curl::Easy.new(TestServlet.url)589 curl.http('PURGE')590 assert_equal 'PURGE', curl.body_str591 end592 def test_head_remote593 curl = Curl::Easy.new(TestServlet.url)594 curl.http_head595 redirect = curl.header_str.match(/Location: (.*)/)596 assert_equal '', curl.body_str597 assert_match '/nonexistent', redirect[1]598 end599 def test_head_accessor600 curl = Curl::Easy.new(TestServlet.url)601 curl.head = true602 curl.perform603 redirect = curl.header_str.match(/Location: (.*)/)604 assert_equal '', curl.body_str605 assert_match '/nonexistent', redirect[1]606 curl.head = false607 curl.perform608 assert_equal 'GET', curl.body_str609 end610 def test_put_remote611 curl = Curl::Easy.new(TestServlet.url)612 curl.headers['Content-Type'] = 'application/json'613 assert curl.http_put("message")614 assert_match /^PUT/, curl.body_str615 assert_match /message$/, curl.body_str616 assert_match /application\/json/, curl.header_str617 end 618 619 def test_put_data620 curl = Curl::Easy.new(TestServlet.url)621 curl.put_data = 'message'622 623 curl.perform624 625 assert_match /^PUT/, curl.body_str626 assert_match /message$/, curl.body_str627 end628 def test_put_nil_data_no_crash629 curl = Curl::Easy.new(TestServlet.url)630 curl.put_data = nil631 632 curl.perform633 end634 def test_put_remote_file635 curl = Curl::Easy.new(TestServlet.url)636 File.open(__FILE__,'r') do|f|637 assert curl.http_put(f)638 end639 assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str640 end641 642 def test_put_class_method643 count = 0644 curl = Curl::Easy.http_put(TestServlet.url,File.open(__FILE__,'rb')) do|c|645 count += 1646 assert_equal Curl::Easy, c.class647 end648 assert_equal 1, count649 assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str650 end651 # Generate a self-signed cert with652 # openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 \653 # -keyout tests/cert.pem -out tests/cert.pem654 def test_cert655 curl = Curl::Easy.new(TestServlet.url)656 curl.cert= File.join(File.dirname(__FILE__),"cert.pem")657 assert_match /cert.pem$/,curl.cert658 end659 def test_cert_with_password660 curl = Curl::Easy.new(TestServlet.url)661 curl.cert= File.join(File.dirname(__FILE__),"cert.pem:password")662 assert_match /cert.pem$/,curl.cert663 end664 def test_cert_type665 curl = Curl::Easy.new(TestServlet.url)666 curl.certtype= "DER"667 assert_equal "DER", curl.certtype668 end669 def test_default_certtype670 curl = Curl::Easy.new(TestServlet.url)671 assert_nil curl.certtype672 curl.certtype = "PEM"673 assert_equal "PEM", curl.certtype674 end675 # Generate a CA cert with instructions at676 # http://technocage.com/~caskey/openssl/677 def test_ca_cert678 curl = Curl::Easy.new(TestServlet.url)679 curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")680 assert_match /cacert.pem$/, curl.cacert681 end682 def test_user_agent683 curl = Curl::Easy.new(TestServlet.url)684 curl.useragent= "Curb-Easy/Ruby"685 assert_equal "Curb-Easy/Ruby",curl.useragent686 end687 def test_username_password688 curl = Curl::Easy.new(TestServlet.url)689 curl.username = "foo"690 curl.password = "bar"691 if !curl.username.nil?692 assert_equal "foo", curl.username693 assert_equal "bar", curl.password694 else695 curl.userpwd = "foo:bar"696 end697 curl.http_auth_types = :basic698 #curl.verbose = true699 curl.perform700 assert_equal 'Basic Zm9vOmJhcg==', $auth_header701 $auth_header = nil702 # curl checks the auth type supported by the server, so we have to create a 703 # new easy handle if we're going to change the auth type...704 curl = Curl::Easy.new(TestServlet.url)705 curl.username = "foo"706 curl.password = "bar"707 if curl.username.nil?708 curl.userpwd = "foo:bar"709 end710 curl.http_auth_types = :ntlm711 curl.perform712 assert_equal 'NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=', $auth_header713 end714 def test_primary_ip715 curl = Curl::Easy.new(TestServlet.url)716 if curl.respond_to?(:primary_ip)717 curl.perform718 assert_equal '127.0.0.1', curl.primary_ip719 end720 end721 def test_post_streaming722 readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))723 724 pf = Curl::PostField.file("filename", readme)725 easy = Curl::Easy.new726 easy.url = TestServlet.url727 easy.multipart_form_post = true728 easy.http_post(pf)729 assert_not_equal(0,easy.body_str.size)730 assert_equal(easy.body_str,File.read(readme))731 end732 def test_easy_close733 easy = Curl::Easy.new734 easy.close735 easy.url = TestServlet.url736 easy.http_get737 end738 def test_easy_reset739 easy = Curl::Easy.new740 easy.url = TestServlet.url + "?query=foo"741 easy.http_get742 settings = easy.reset743 assert settings.key?(:url)744 assert settings.key?(:body_data)745 assert settings.key?(:header_data)746 easy.url = TestServlet.url747 easy.http_get748 end749 def test_easy_use_http_versions750 easy = Curl::Easy.new751 easy.url = TestServlet.url + "?query=foo"752 #puts "http none: #{Curl::HTTP_NONE.inspect}"753 #puts "http1.0: #{Curl::HTTP_1_0.inspect}"754 #puts "http1.1: #{Curl::HTTP_1_1.inspect}"755 easy.version = Curl::HTTP_1_1756 #easy.verbose = true757 easy.http_get758 end759 def test_easy_http_verbs760 curl = Curl::Easy.new(TestServlet.url)761 curl.http_delete762 assert_equal 'DELETE', curl.body_str763 curl.http_get764 assert_equal 'GET', curl.body_str765 curl.http_post766 assert_equal "POST\n", curl.body_str767 curl.http('PURGE')768 assert_equal 'PURGE', curl.body_str769 curl.http_put('hello')770 assert_equal "PUT\nhello", curl.body_str771 curl.http('COPY')772 assert_equal 'COPY', curl.body_str773 end774 def test_easy_http_verbs_must_respond_to_str775 # issue http://github.com/taf2/curb/issues#issue/45776 assert_nothing_raised do777 c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(:get)778 end779 assert_raise RuntimeError do780 c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(FooNoToS.new)781 end782 end783 # http://github.com/taf2/curb/issues/#issue/33784 def test_easy_http_verbs_with_errors785 curl = Curl::Easy.new("http://127.0.0.1:9012/") # test will fail if http server on port 9012786 assert_raise Curl::Err::ConnectionFailedError do787 curl.http_delete788 end789 curl.url = TestServlet.url790 curl.http_get791 assert_equal 'GET', curl.body_str792 end793 def test_easy_can_put_with_content_length794 curl = Curl::Easy.new(TestServlet.url)795 rd, wr = IO.pipe796 buf = (("hello")* (1000 / 5))797 producer = Thread.new do798 5.times do799 wr << buf800 sleep 0.1 # act as a slow producer801 end802 end803 consumer = Thread.new do804 #curl.verbose = true805 curl.headers['Content-Length'] = buf.size * 5806 curl.headers['User-Agent'] = "Something else"807 curl.headers['Content-Type'] = "text/javascript"808 curl.headers['Date'] = Time.now.httpdate809 curl.headers['Host'] = 's3.amazonaws.com'810 curl.headers['Accept'] = '*/*'811 curl.headers['Authorization'] = 'Foo Bar Biz Baz'812 curl.http_put(rd)813 assert_match /^PUT/, curl.body_str814 assert_match /hello$/, curl.body_str815 curl.header_str816 curl.body_str817 end818 producer.join819 wr.close820 consumer.join821 end822 include TestServerMethods 823 def setup824 server_setup825 end826end...

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = Curl::Easy.new("http://www.ruby-lang.org")2c = Curl::Easy.new("http://www.ruby-lang.org")3c = Curl::Easy.new("http://www.ruby-lang.org")4c = Curl::Easy.new("http://www.ruby-lang.org")5c = Curl::Easy.new("http://www.ruby-lang.org")6c = Curl::Easy.new("http://www.ruby-lang.org")7c = Curl::Easy.new("http://www.ruby-lang.org")8c = Curl::Easy.new("http://www.ruby-lang.org")9c = Curl::Easy.new("http://www.ruby-lang.org")10c = Curl::Easy.new("http://www.ruby-lang.org")11c = Curl::Easy.new("http://www.ruby-lang.org")

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = Curl::Easy.new("http://www.google.com")2c = Curl::Easy.new("http://www.google.com")3c = Curl::Easy.new("http://www.google.com")4c = Curl::Easy.new("http://www.google.com")5c = Curl::Easy.new("http://www.google.com")6c = Curl::Easy.new("http://www.google.com")7c = Curl::Easy.new("http://www.google.com")8c = Curl::Easy.new("http://www.google.com")9c = Curl::Easy.new("http://www.google.com")10c = Curl::Easy.new("http://www.google.com")

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = Curl::Easy.new('http://www.ruby-lang.org')2c = Curl::Easy.new('http://www.ruby-lang.org')3m.add(c)4c = Curl::Easy.new('http://www.ruby-lang.org')5c.http_post(Curl::PostField.content('name', 'value'))6c = Curl::Easy.new('http://www.ruby-lang.org')7c.http_post(Curl::PostField.content('name', 'value'))8c = Curl::Easy.new('http://www.ruby-lang.org')9c.http_post(Curl::PostField.content('name', 'value'))10c = Curl::Easy.new('http://www.ruby-lang.org')11c.http_post(Curl::PostField.content('name', 'value'))12c = Curl::Easy.new('http://www.ruby-lang.org')13c.http_post(Curl::PostField.content('name', 'value'))14c = Curl::Easy.new('http://www.ruby-lang.org')15c.http_post(Curl::PostField.content('name', 'value'))16c = Curl::Easy.new('http://www.ruby-lang.org')17c.http_post(Curl::PostField.content('name', 'value'))

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1curl = Curl::Easy.new("http://www.ruby-lang.org/")2curl = Curl::Easy.new("http://www.ruby-lang.org/")3multi.add(curl)4curl = Curl::Easy.new("http://www.ruby-lang.org/")5curl = Curl::Easy.new("http://www.ruby-lang.org/")6multi.add(curl)7curl = Curl::Easy.new("http://www.ruby-lang.org/")8curl.download("ruby.html")9curl = Curl::Easy.new("http://www.ruby-lang.org/")10multi.add(curl)11curl.download("ruby.html")12curl = Curl::Easy.new("http://www.ruby-lang.org/")13curl = Curl::Easy.new("http://www.ruby-lang.org/")14multi.add(curl)

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = Curl::Easy.new('http://www.google.com')2c = Curl::Easy.new('http://www.google.com')3c = Curl::Easy.new('http://www.google.com')4c = Curl::Easy.new('http://www.google.com')5c = Curl::Easy.new('http://www.google.com')6c = Curl::Easy.new('http://www.google.com')7c = Curl::Easy.new('http://www.google.com')8c = Curl::Easy.new('http://www.google.com')

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = Curl::Easy.new('http://www.google.com/')2open('http://www.google.com/') { |f|3}4Net::HTTP.get('www.google.com', '/')5Google.get('/')6client.get_content('http://www.google.com/')7client.get_content('http://www.google.com/')8client.get_content('http://www.google.com/')9client.get_content('http://www.google.com/')10client.get_content('http://www.google.com/')11client.get_content('http://www.google.com/')12client.get_content('http://www.google.com/')

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = Curl::Easy.new("http://www.rubyinside.com/")2c = Curl::Easy.new("http://www.rubyinside.com/")3c = Curl::Easy.new("http://www.rubyinside.com/")4c = Curl::Easy.new("http://www.rubyinside.com/")5c = Curl::Easy.new("http://www.rubyinside.com/")6c = Curl::Easy.new("http://www.rubyinside.com/")7c = Curl::Easy.new("http://www.rubyinside.com/")8c = Curl::Easy.new("http://www.rubyinside.com/")9c = Curl::Easy.new("http://www.rubyinside.com/")

Full Screen

Full Screen

body_str

Using AI Code Generation

copy

Full Screen

1c = CurlFu.get('http://www.google.com')2doc = Nokogiri::HTML(c.body_str)3doc.css('a').each do |link|

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