taf2-curb 0.5.1.0 → 0.5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +8 -7
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +32 -5
- data/lib/curb.rb +70 -3
- data/tests/tc_curl_multi.rb +23 -0
- metadata +16 -16
    
        data/README
    CHANGED
    
    | @@ -17,9 +17,9 @@ Ruby license. See the LICENSE file for the gory details. | |
| 17 17 |  | 
| 18 18 | 
             
            ## You will need
         | 
| 19 19 |  | 
| 20 | 
            -
            + A working Ruby installation (1.8+, tested with 1.8. | 
| 21 | 
            -
            + A working (lib)curl installation, with development stuff (7.5+, tested with 7. | 
| 22 | 
            -
            + A sane build environment
         | 
| 20 | 
            +
            + A working Ruby installation (1.8+, tested with 1.8.6, 1.8.7, 1.9.1, and 1.9.2)
         | 
| 21 | 
            +
            + A working (lib)curl installation, with development stuff (7.5+, tested with 7.19.x)
         | 
| 22 | 
            +
            + A sane build environment (e.g. gcc, make)
         | 
| 23 23 |  | 
| 24 24 | 
             
            ## Installation...
         | 
| 25 25 |  | 
| @@ -36,10 +36,9 @@ them like so: | |
| 36 36 |  | 
| 37 37 | 
             
                $ rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever'
         | 
| 38 38 |  | 
| 39 | 
            -
             | 
| 39 | 
            +
            Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms.
         | 
| 40 40 | 
             
            If you do use another platform and experience problems, or if you can 
         | 
| 41 | 
            -
            expand on the above instructions, please  | 
| 42 | 
            -
            list on Curb's Rubyforge page.
         | 
| 41 | 
            +
            expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues
         | 
| 43 42 |  | 
| 44 43 | 
             
            Curb has fairly extensive RDoc comments in the source. You can build the
         | 
| 45 44 | 
             
            documentation with:
         | 
| @@ -106,7 +105,7 @@ documentation with: | |
| 106 105 | 
             
                c.multipart_form_post = true
         | 
| 107 106 | 
             
                c.http_post(Curl::PostField.file('myfile.rb'))
         | 
| 108 107 |  | 
| 109 | 
            -
            ### Multi Interface (Basic):
         | 
| 108 | 
            +
            ### Multi Interface (Basic HTTP GET):
         | 
| 110 109 |  | 
| 111 110 | 
             
                # make multiple GET requests
         | 
| 112 111 | 
             
                easy_options = {:follow_location => true}
         | 
| @@ -117,6 +116,8 @@ documentation with: | |
| 117 116 | 
             
                  puts easy.last_effective_url
         | 
| 118 117 | 
             
                end
         | 
| 119 118 |  | 
| 119 | 
            +
            ### Multi Interface (Basic HTTP POST):
         | 
| 120 | 
            +
             | 
| 120 121 | 
             
                # make multiple POST requests
         | 
| 121 122 | 
             
                easy_options = {:follow_location => true, :multipart_form_post => true}
         | 
| 122 123 | 
             
                multi_options = {:pipeline => true}
         | 
    
        data/ext/curb.h
    CHANGED
    
    | @@ -20,11 +20,11 @@ | |
| 20 20 | 
             
            #include "curb_macros.h"
         | 
| 21 21 |  | 
| 22 22 | 
             
            // These should be managed from the Rake 'release' task.
         | 
| 23 | 
            -
            #define CURB_VERSION   "0.5. | 
| 24 | 
            -
            #define CURB_VER_NUM    | 
| 23 | 
            +
            #define CURB_VERSION   "0.5.2.0"
         | 
| 24 | 
            +
            #define CURB_VER_NUM   520
         | 
| 25 25 | 
             
            #define CURB_VER_MAJ   0
         | 
| 26 26 | 
             
            #define CURB_VER_MIN   5
         | 
| 27 | 
            -
            #define CURB_VER_MIC    | 
| 27 | 
            +
            #define CURB_VER_MIC   2
         | 
| 28 28 | 
             
            #define CURB_VER_PATCH 0
         | 
| 29 29 |  | 
| 30 30 |  | 
    
        data/ext/curb_easy.c
    CHANGED
    
    | @@ -1954,6 +1954,27 @@ static VALUE ruby_curl_easy_set_head_option(VALUE self, VALUE onoff) { | |
| 1954 1954 |  | 
| 1955 1955 | 
             
              return onoff;
         | 
| 1956 1956 | 
             
            }
         | 
| 1957 | 
            +
            /*
         | 
| 1958 | 
            +
             *call-seq:
         | 
| 1959 | 
            +
             * easy = Curl::Easy.new("url") do|c|
         | 
| 1960 | 
            +
             *  c.delete = true
         | 
| 1961 | 
            +
             * end
         | 
| 1962 | 
            +
             * easy.perform
         | 
| 1963 | 
            +
             */
         | 
| 1964 | 
            +
            static VALUE ruby_curl_easy_set_delete_option(VALUE self, VALUE onoff) {
         | 
| 1965 | 
            +
              ruby_curl_easy *rbce;
         | 
| 1966 | 
            +
             | 
| 1967 | 
            +
              Data_Get_Struct(self, ruby_curl_easy, rbce);
         | 
| 1968 | 
            +
             | 
| 1969 | 
            +
              if( onoff == Qtrue ) {
         | 
| 1970 | 
            +
                curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, "DELETE");
         | 
| 1971 | 
            +
              }
         | 
| 1972 | 
            +
              else {
         | 
| 1973 | 
            +
                curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, NULL);
         | 
| 1974 | 
            +
              }
         | 
| 1975 | 
            +
             | 
| 1976 | 
            +
              return onoff;
         | 
| 1977 | 
            +
            }
         | 
| 1957 1978 |  | 
| 1958 1979 | 
             
            /*
         | 
| 1959 1980 | 
             
             * call-seq:
         | 
| @@ -2554,11 +2575,16 @@ static VALUE ruby_curl_easy_inspect(VALUE self) { | |
| 2554 2575 | 
             
              char buf[64];
         | 
| 2555 2576 | 
             
              ruby_curl_easy *rbce;
         | 
| 2556 2577 | 
             
              Data_Get_Struct(self, ruby_curl_easy, rbce);
         | 
| 2557 | 
            -
               | 
| 2558 | 
            -
               | 
| 2559 | 
            -
             | 
| 2560 | 
            -
             | 
| 2561 | 
            -
             | 
| 2578 | 
            +
              /* if we don't have a url set... we'll crash... */
         | 
| 2579 | 
            +
              if(rbce->url != Qnil && rb_type(rbce->url) == T_STRING) {
         | 
| 2580 | 
            +
                size_t len = 13+((RSTRING_LEN(rbce->url) > 50) ? 50 : RSTRING_LEN(rbce->url));
         | 
| 2581 | 
            +
                /* "#<Net::HTTP http://www.google.com/:80 open=false>" */
         | 
| 2582 | 
            +
                memcpy(buf,"#<Curl::Easy ", 13);
         | 
| 2583 | 
            +
                memcpy(buf+13,RSTRING_PTR(rbce->url), (len - 13));
         | 
| 2584 | 
            +
                buf[len-1] = '>';
         | 
| 2585 | 
            +
                return rb_str_new(buf,len);
         | 
| 2586 | 
            +
              }
         | 
| 2587 | 
            +
              return rb_str_new2("#<Curl::Easy");
         | 
| 2562 2588 | 
             
            }
         | 
| 2563 2589 |  | 
| 2564 2590 |  | 
| @@ -2847,6 +2873,7 @@ void init_curb_easy() { | |
| 2847 2873 | 
             
              rb_define_method(cCurlEasy, "http_head", ruby_curl_easy_perform_head, 0);
         | 
| 2848 2874 | 
             
              rb_define_method(cCurlEasy, "http_put", ruby_curl_easy_perform_put, 1);
         | 
| 2849 2875 | 
             
              rb_define_method(cCurlEasy, "head=", ruby_curl_easy_set_head_option, 1);
         | 
| 2876 | 
            +
              rb_define_method(cCurlEasy, "delete=", ruby_curl_easy_set_delete_option, 1);
         | 
| 2850 2877 |  | 
| 2851 2878 | 
             
              /* Post-perform info methods */
         | 
| 2852 2879 | 
             
              rb_define_method(cCurlEasy, "body_str", ruby_curl_easy_body_str_get, 0);
         | 
    
        data/lib/curb.rb
    CHANGED
    
    | @@ -106,20 +106,87 @@ module Curl | |
| 106 106 |  | 
| 107 107 | 
             
                    urls_with_config.each do|conf|
         | 
| 108 108 | 
             
                      c = conf.dup # avoid being destructive to input
         | 
| 109 | 
            -
                      url | 
| 110 | 
            -
                      fields | 
| 111 | 
            -
                       | 
| 109 | 
            +
                      url     = c.delete(:url)
         | 
| 110 | 
            +
                      fields  = c.delete(:post_fields)
         | 
| 111 | 
            +
                      headers = c.delete(:headers)
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                      easy    = Curl::Easy.new(url)
         | 
| 112 114 | 
             
                      # set the post post using the url fields
         | 
| 113 115 | 
             
                      easy.post_body = fields.map{|f,k| "#{easy.escape(f)}=#{easy.escape(k)}"}.join('&')
         | 
| 114 116 | 
             
                      # configure the easy handle
         | 
| 115 117 | 
             
                      easy_options.each do|k,v|
         | 
| 116 118 | 
             
                        easy.send("#{k}=",v)
         | 
| 117 119 | 
             
                      end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                      # headers is a special key
         | 
| 122 | 
            +
                      headers.each {|k,v| easy.headers[k] = v } if headers
         | 
| 123 | 
            +
             | 
| 118 124 | 
             
                      easy.on_complete {|curl| blk.call curl } if blk
         | 
| 119 125 | 
             
                      m.add(easy)
         | 
| 120 126 | 
             
                    end
         | 
| 121 127 | 
             
                    m.perform
         | 
| 122 128 | 
             
                  end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                  # call-seq:
         | 
| 131 | 
            +
                  #
         | 
| 132 | 
            +
                  # Curl::Multi.http( [
         | 
| 133 | 
            +
                  #   { :url => 'url1', :method => :post,
         | 
| 134 | 
            +
                  #     :post_fields => {'field1' => 'value1', 'field2' => 'value2'} },
         | 
| 135 | 
            +
                  #   { :url => 'url2', :method => :get,
         | 
| 136 | 
            +
                  #     :follow_location => true, :max_redirects => 3 },
         | 
| 137 | 
            +
                  #   { :url => 'url3', :method => :put, :put_data => File.open('file.txt','rb') },
         | 
| 138 | 
            +
                  #   { :url => 'url4', :method => :head }
         | 
| 139 | 
            +
                  # ], {:pipeline => true})
         | 
| 140 | 
            +
                  #
         | 
| 141 | 
            +
                  # Blocking call to issue multiple HTTP requests with varying verb's.
         | 
| 142 | 
            +
                  #
         | 
| 143 | 
            +
                  # urls_with_config: is a hash of url's pointing to the easy handle options as well as the special option :method, that can by one of [:get, :post, :put, :delete, :head], when no verb is provided e.g. :method => nil -> GET is used
         | 
| 144 | 
            +
                  # multi_options: options for the multi handle 
         | 
| 145 | 
            +
                  # blk: a callback, that yeilds when a handle is completed
         | 
| 146 | 
            +
                  #
         | 
| 147 | 
            +
                  def http(urls_with_config, multi_options, &blk)
         | 
| 148 | 
            +
                    m = Curl::Multi.new
         | 
| 149 | 
            +
                    # configure the multi handle
         | 
| 150 | 
            +
                    multi_options.each { |k,v| m.send("#{k}=", v) }
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                    urls_with_config.each do|conf|
         | 
| 153 | 
            +
                      c = conf.dup # avoid being destructive to input
         | 
| 154 | 
            +
                      url     = c.delete(:url)
         | 
| 155 | 
            +
                      method  = c.delete(:method)
         | 
| 156 | 
            +
                      headers = c.delete(:headers)
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                      easy    = Curl::Easy.new(url)
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                      case method
         | 
| 161 | 
            +
                      when :post
         | 
| 162 | 
            +
                        fields = c.delete(:post_fields)
         | 
| 163 | 
            +
                        # set the post post using the url fields
         | 
| 164 | 
            +
                        easy.post_body = fields.map{|f,k| "#{easy.escape(f)}=#{easy.escape(k)}"}.join('&')
         | 
| 165 | 
            +
                      when :put
         | 
| 166 | 
            +
                        easy.put_data = c.delete(:put_data)
         | 
| 167 | 
            +
                      when :head
         | 
| 168 | 
            +
                        easy.head = true
         | 
| 169 | 
            +
                      when :delete
         | 
| 170 | 
            +
                        easy.delete = true
         | 
| 171 | 
            +
                      when :get
         | 
| 172 | 
            +
                      else
         | 
| 173 | 
            +
                        # XXX: nil is treated like a GET
         | 
| 174 | 
            +
                      end
         | 
| 175 | 
            +
             | 
| 176 | 
            +
                      # headers is a special key
         | 
| 177 | 
            +
                      headers.each {|k,v| easy.headers[k] = v } if headers
         | 
| 178 | 
            +
             
         | 
| 179 | 
            +
                      #
         | 
| 180 | 
            +
                      # use the remaining options as specific configuration to the easy handle
         | 
| 181 | 
            +
                      # bad options should raise an undefined method error
         | 
| 182 | 
            +
                      #
         | 
| 183 | 
            +
                      c.each { |k,v| easy.send("#{k}=",v) }
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                      easy.on_complete {|curl,code| blk.call(curl,code,method) } if blk
         | 
| 186 | 
            +
                      m.add(easy)
         | 
| 187 | 
            +
                    end
         | 
| 188 | 
            +
                    m.perform
         | 
| 189 | 
            +
                  end
         | 
| 123 190 | 
             
                end
         | 
| 124 191 | 
             
              end
         | 
| 125 192 | 
             
            end
         | 
    
        data/tests/tc_curl_multi.rb
    CHANGED
    
    | @@ -325,6 +325,29 @@ class TestCurbCurlMulti < Test::Unit::TestCase | |
| 325 325 | 
             
                end
         | 
| 326 326 | 
             
              end
         | 
| 327 327 |  | 
| 328 | 
            +
              def test_multi_easy_http_01
         | 
| 329 | 
            +
                urls = [
         | 
| 330 | 
            +
                  { :url => TestServlet.url + '?q=1', :method => :post, :post_fields => {'field1' => 'value1', 'k' => 'j'}},
         | 
| 331 | 
            +
                  { :url => TestServlet.url + '?q=2', :method => :post, :post_fields => {'field2' => 'value2', 'foo' => 'bar', 'i' => 'j' }},
         | 
| 332 | 
            +
                  { :url => TestServlet.url + '?q=3', :method => :post, :post_fields => {'field3' => 'value3', 'field4' => 'value4'}},
         | 
| 333 | 
            +
                  { :url => TestServlet.url, :method => :put, :put_data => "message", 
         | 
| 334 | 
            +
                    :headers => {'Content-Type' => 'application/json' } },
         | 
| 335 | 
            +
                  { :url => TestServlet.url, :method => :get }
         | 
| 336 | 
            +
                ]
         | 
| 337 | 
            +
                Curl::Multi.http(urls, {:pipeline => true}) do|easy, code, method|
         | 
| 338 | 
            +
                  assert_equal nil, code
         | 
| 339 | 
            +
                  case method
         | 
| 340 | 
            +
                  when :post
         | 
| 341 | 
            +
                    assert_match /POST/, easy.body_str
         | 
| 342 | 
            +
                  when :get
         | 
| 343 | 
            +
                    assert_match /GET/, easy.body_str
         | 
| 344 | 
            +
                  when :put
         | 
| 345 | 
            +
                    assert_match /PUT/, easy.body_str
         | 
| 346 | 
            +
                  end
         | 
| 347 | 
            +
                  #puts "#{easy.body_str.inspect}, #{method.inspect}, #{code.inspect}"
         | 
| 348 | 
            +
                end
         | 
| 349 | 
            +
              end
         | 
| 350 | 
            +
             | 
| 328 351 | 
             
              def test_mutli_recieves_500
         | 
| 329 352 | 
             
                m = Curl::Multi.new
         | 
| 330 353 | 
             
                e = Curl::Easy.new("http://127.0.0.1:9129/methods")
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: taf2-curb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Ross Bamford
         | 
| @@ -10,7 +10,7 @@ autorequire: | |
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 12 |  | 
| 13 | 
            -
            date: 2009-08- | 
| 13 | 
            +
            date: 2009-08-23 00:00:00 -07:00
         | 
| 14 14 | 
             
            default_executable: 
         | 
| 15 15 | 
             
            dependencies: []
         | 
| 16 16 |  | 
| @@ -32,18 +32,18 @@ files: | |
| 32 32 | 
             
            - lib/curb.rb
         | 
| 33 33 | 
             
            - lib/curl.rb
         | 
| 34 34 | 
             
            - ext/curb.c
         | 
| 35 | 
            -
            - ext/curb_easy.c
         | 
| 36 | 
            -
            - ext/curb_errors.c
         | 
| 37 | 
            -
            - ext/curb_multi.c
         | 
| 38 35 | 
             
            - ext/curb_postfield.c
         | 
| 36 | 
            +
            - ext/curb_multi.c
         | 
| 37 | 
            +
            - ext/curb_errors.c
         | 
| 38 | 
            +
            - ext/curb_easy.c
         | 
| 39 39 | 
             
            - ext/curb_upload.c
         | 
| 40 | 
            -
            - ext/curb.h
         | 
| 41 40 | 
             
            - ext/curb_easy.h
         | 
| 42 41 | 
             
            - ext/curb_errors.h
         | 
| 42 | 
            +
            - ext/curb_upload.h
         | 
| 43 43 | 
             
            - ext/curb_macros.h
         | 
| 44 | 
            -
            - ext/ | 
| 44 | 
            +
            - ext/curb.h
         | 
| 45 45 | 
             
            - ext/curb_postfield.h
         | 
| 46 | 
            -
            - ext/ | 
| 46 | 
            +
            - ext/curb_multi.h
         | 
| 47 47 | 
             
            has_rdoc: true
         | 
| 48 48 | 
             
            homepage: http://curb.rubyforge.org/
         | 
| 49 49 | 
             
            licenses: 
         | 
| @@ -74,15 +74,15 @@ signing_key: | |
| 74 74 | 
             
            specification_version: 2
         | 
| 75 75 | 
             
            summary: Ruby libcurl bindings
         | 
| 76 76 | 
             
            test_files: 
         | 
| 77 | 
            -
            - tests/ | 
| 77 | 
            +
            - tests/tc_curl_multi.rb
         | 
| 78 | 
            +
            - tests/tc_curl_postfield.rb
         | 
| 78 79 | 
             
            - tests/bug_curb_easy_blocks_ruby_threads.rb
         | 
| 79 | 
            -
            - tests/ | 
| 80 | 
            -
            - tests/bug_multi_segfault.rb
         | 
| 80 | 
            +
            - tests/unittests.rb
         | 
| 81 81 | 
             
            - tests/bug_require_last_or_segfault.rb
         | 
| 82 | 
            -
            - tests/ | 
| 83 | 
            -
            - tests/require_last_or_segfault_script.rb
         | 
| 82 | 
            +
            - tests/bug_instance_post_differs_from_class_post.rb
         | 
| 84 83 | 
             
            - tests/tc_curl_download.rb
         | 
| 84 | 
            +
            - tests/alltests.rb
         | 
| 85 | 
            +
            - tests/helper.rb
         | 
| 85 86 | 
             
            - tests/tc_curl_easy.rb
         | 
| 86 | 
            -
            - tests/ | 
| 87 | 
            -
            - tests/ | 
| 88 | 
            -
            - tests/unittests.rb
         | 
| 87 | 
            +
            - tests/bug_multi_segfault.rb
         | 
| 88 | 
            +
            - tests/require_last_or_segfault_script.rb
         |