curb 0.7.15 → 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dce5f49b09bacccf705e3d25ba29031dd4fc82c2721860eef02bb4a8af2dd0e2
4
+ data.tar.gz: 9456ed69688f2236bdd17f338e26faaf46b91f0fd4e51b3a48d5551ff8fdc433
5
+ SHA512:
6
+ metadata.gz: df6ab81576ef567878331724c1600c59ff923be34d3a71bd31d07e4999880743e73c31a502bab8aaece54099fd5142bf954dbf004fffd38f0e6698750e3f9682
7
+ data.tar.gz: 5b7b867979da88d328e9f71a4a6eb7183430de26902311cb8678b443a6c53cf50aa62952f277bc2c2821bafc2af48c0e28067f7dce512ff7c2912b195bc27ad5
data/README.markdown ADDED
@@ -0,0 +1,283 @@
1
+ # Curb - Libcurl bindings for Ruby [![Build Status](https://travis-ci.org/taf2/curb.svg?branch=master)](https://travis-ci.org/taf2/curb)
2
+
3
+ * [rubydoc rdoc](http://www.rubydoc.info/github/taf2/curb/)
4
+ * [github project](http://github.com/taf2/curb/tree/master)
5
+
6
+ Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
7
+ libcurl(3), a fully-featured client-side URL transfer library.
8
+ cURL and libcurl live at [http://curl.haxx.se/](http://curl.haxx.se/) .
9
+
10
+ Curb is a work-in-progress, and currently only supports libcurl's `easy` and `multi` modes.
11
+
12
+ ## License
13
+
14
+ Curb is copyright (c)2006 Ross Bamford, and released under the terms of the
15
+ Ruby license. See the LICENSE file for the gory details.
16
+
17
+ ## You will need
18
+
19
+ * A working Ruby installation (`1.8.7+` will work but `2.1+` preferred)
20
+ * A working libcurl development installation
21
+ (Ideally one of the versions listed in the compatibility chart below that maps to your `curb` version)
22
+ * A sane build environment (e.g. gcc, make)
23
+
24
+ ## Version Compatibility chart
25
+
26
+ A **non-exhaustive** set of compatibility versions of the libcurl library
27
+ with this gem are as follows. (Note that these are only the ones that have been
28
+ tested and reported to work across a variety of platforms / rubies)
29
+
30
+ | Gem Version | Release Date | libcurl versions |
31
+ | ----------- | ----------- | ---------------- |
32
+ | 0.9.8 | Jan 2019 | 7.58 - 7.63 |
33
+ | 0.9.7 | Nov 2018 | 7.56 - 7.60 |
34
+ | 0.9.6 | May 2018 | 7.51 - 7.59 |
35
+ | 0.9.5 | May 2018 | 7.51 - 7.59 |
36
+ | 0.9.4 | Aug 2017 | 7.41 - 7.58 |
37
+ | 0.9.3 | Apr 2016 | 7.26 - 7.58 |
38
+
39
+ ## Installation...
40
+
41
+ ... will usually be as simple as:
42
+
43
+ $ gem install curb
44
+
45
+ On Windows, make sure you're using the [DevKit](http://rubyinstaller.org/downloads/) and
46
+ the [development version of libcurl](http://curl.haxx.se/gknw.net/7.39.0/dist-w32/curl-7.39.0-devel-mingw32.zip). Unzip, then run this in your command
47
+ line (alter paths to your curl location, but remember to use forward slashes):
48
+
49
+ gem install curb --platform=ruby -- --with-curl-lib=C:/curl-7.39.0-devel-mingw32/lib --with-curl-include=C:/curl-7.39.0-devel-mingw32/include
50
+
51
+ Note that with Windows moving from one method of compiling to another as of Ruby `2.4` (DevKit -> MYSYS2),
52
+ the usage of Ruby `2.4+` with this gem on windows is unlikely to work. It is advised to use the
53
+ latest version of Ruby 2.3 available [HERE](https://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.3.3.exe)
54
+
55
+ Or, if you downloaded the archive:
56
+
57
+ $ rake compile && rake install
58
+
59
+ If you have a weird setup, you might need extconf options. In this case, pass
60
+ them like so:
61
+
62
+ $ rake compile EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever' && rake install
63
+
64
+ Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms.
65
+ If you do use another platform and experience problems, or if you can
66
+ expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues
67
+
68
+ On Ubuntu, the dependencies can be satisfied by installing the following packages:
69
+
70
+ 18.04 and onwards
71
+
72
+ $ sudo apt-get install libcurl4 libcurl3-gnutls libcurl4-openssl-dev
73
+
74
+ < 18.04
75
+
76
+ $ sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev
77
+
78
+ On RedHat:
79
+
80
+ $ sudo yum install ruby-devel libcurl-devel openssl-devel
81
+
82
+ Curb has fairly extensive RDoc comments in the source. You can build the
83
+ documentation with:
84
+
85
+ $ rake doc
86
+
87
+ ## Usage & examples
88
+
89
+ Curb provides two classes:
90
+
91
+ * `Curl::Easy` - simple API, for day-to-day tasks.
92
+ * `Curl::Multi` - more advanced API, for operating on multiple URLs simultaneously.
93
+
94
+ To use either, you will need to require the curb gem:
95
+
96
+ ```ruby
97
+ require 'curb'
98
+ ```
99
+
100
+ ### Super simple API (less typing)
101
+
102
+ ```ruby
103
+ http = Curl.get("http://www.google.com/")
104
+ puts http.body_str
105
+
106
+ http = Curl.post("http://www.google.com/", {:foo => "bar"})
107
+ puts http.body_str
108
+
109
+ http = Curl.get("http://www.google.com/") do |http|
110
+ http.headers['Cookie'] = 'foo=1;bar=2'
111
+ end
112
+ puts http.body_str
113
+ ```
114
+
115
+ ### Simple fetch via HTTP:
116
+
117
+ ```ruby
118
+ c = Curl::Easy.perform("http://www.google.co.uk")
119
+ puts c.body_str
120
+ ```
121
+
122
+ Same thing, more manual:
123
+
124
+ ```ruby
125
+ c = Curl::Easy.new("http://www.google.co.uk")
126
+ c.perform
127
+ puts c.body_str
128
+ ```
129
+
130
+ ### Additional config:
131
+
132
+ ```ruby
133
+ Curl::Easy.perform("http://www.google.co.uk") do |curl|
134
+ curl.headers["User-Agent"] = "myapp-0.0"
135
+ curl.verbose = true
136
+ end
137
+ ```
138
+
139
+ Same thing, more manual:
140
+
141
+ ```ruby
142
+ c = Curl::Easy.new("http://www.google.co.uk") do |curl|
143
+ curl.headers["User-Agent"] = "myapp-0.0"
144
+ curl.verbose = true
145
+ end
146
+
147
+ c.perform
148
+ ```
149
+
150
+ ### HTTP basic authentication:
151
+
152
+ ```ruby
153
+ c = Curl::Easy.new("http://github.com/")
154
+ c.http_auth_types = :basic
155
+ c.username = 'foo'
156
+ c.password = 'bar'
157
+ c.perform
158
+ ```
159
+
160
+ ### HTTP "insecure" SSL connections (like curl -k, --insecure) to avoid Curl::Err::SSLCACertificateError:
161
+
162
+ ```ruby
163
+ c = Curl::Easy.new("https://github.com/")
164
+ c.ssl_verify_peer = false
165
+ c.perform
166
+ ```
167
+
168
+ ### Supplying custom handlers:
169
+
170
+ ```ruby
171
+ c = Curl::Easy.new("http://www.google.co.uk")
172
+
173
+ c.on_body { |data| print(data) }
174
+ c.on_header { |data| print(data) }
175
+
176
+ c.perform
177
+ ```
178
+
179
+ ### Reusing Curls:
180
+
181
+ ```ruby
182
+ c = Curl::Easy.new
183
+
184
+ ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
185
+ c.url = url
186
+ c.perform
187
+ c.body_str
188
+ end
189
+ ```
190
+
191
+ ### HTTP POST form:
192
+
193
+ ```ruby
194
+ c = Curl::Easy.http_post("http://my.rails.box/thing/create",
195
+ Curl::PostField.content('thing[name]', 'box'),
196
+ Curl::PostField.content('thing[type]', 'storage'))
197
+ ```
198
+
199
+ ### HTTP POST file upload:
200
+
201
+ ```ruby
202
+ c = Curl::Easy.new("http://my.rails.box/files/upload")
203
+ c.multipart_form_post = true
204
+ c.http_post(Curl::PostField.file('thing[file]', 'myfile.rb'))
205
+ ```
206
+
207
+ ### Using HTTP/2
208
+
209
+ ```ruby
210
+ c = Curl::Easy.new("https://http2.akamai.com")
211
+ c.set(:HTTP_VERSION, Curl::HTTP_2_0)
212
+
213
+ c.perform
214
+ puts (c.body_str.include? "You are using HTTP/2 right now!") ? "HTTP/2" : "HTTP/1.x"
215
+ ```
216
+
217
+ ### Multi Interface (Basic HTTP GET):
218
+
219
+ ```ruby
220
+ # make multiple GET requests
221
+ easy_options = {:follow_location => true}
222
+ # Use Curl::CURLPIPE_MULTIPLEX for HTTP/2 multiplexing
223
+ multi_options = {:pipeline => Curl::CURLPIPE_HTTP1}
224
+
225
+ Curl::Multi.get(['url1','url2','url3','url4','url5'], easy_options, multi_options) do|easy|
226
+ # do something interesting with the easy response
227
+ puts easy.last_effective_url
228
+ end
229
+ ```
230
+
231
+ ### Multi Interface (Basic HTTP POST):
232
+
233
+ ```ruby
234
+ # make multiple POST requests
235
+ easy_options = {:follow_location => true, :multipart_form_post => true}
236
+ multi_options = {:pipeline => Curl::CURLPIPE_HTTP1}
237
+
238
+
239
+ url_fields = [
240
+ { :url => 'url1', :post_fields => {'f1' => 'v1'} },
241
+ { :url => 'url2', :post_fields => {'f1' => 'v1'} },
242
+ { :url => 'url3', :post_fields => {'f1' => 'v1'} }
243
+ ]
244
+
245
+ Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
246
+ # do something interesting with the easy response
247
+ puts easy.last_effective_url
248
+ end
249
+ ```
250
+
251
+ ### Multi Interface (Advanced):
252
+
253
+ ```ruby
254
+ responses = {}
255
+ requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
256
+ m = Curl::Multi.new
257
+ # add a few easy handles
258
+ requests.each do |url|
259
+ responses[url] = ""
260
+ c = Curl::Easy.new(url) do|curl|
261
+ curl.follow_location = true
262
+ curl.on_body{|data| responses[url] << data; data.size }
263
+ curl.on_success {|easy| puts "success, add more easy handles" }
264
+ end
265
+ m.add(c)
266
+ end
267
+
268
+ m.perform do
269
+ puts "idling... can do some work here"
270
+ end
271
+
272
+ requests.each do|url|
273
+ puts responses[url]
274
+ end
275
+ ```
276
+
277
+ ### Easy Callbacks
278
+
279
+ * `on_success` is called when the response code is 2xx
280
+ * `on_redirect` is called when the response code is 3xx
281
+ * `on_missing` is called when the response code is 4xx
282
+ * `on_failure` is called when the response code is 5xx
283
+ * `on_complete` is called in all cases.
data/Rakefile CHANGED
@@ -2,15 +2,30 @@
2
2
  #
3
3
  require 'rake/clean'
4
4
  require 'rake/testtask'
5
- require 'rake/rdoctask'
6
5
 
7
6
  CLEAN.include '**/*.o'
8
- CLEAN.include "**/*.#{Config::MAKEFILE_CONFIG['DLEXT']}"
7
+ CLEAN.include "**/*.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
9
8
  CLOBBER.include 'doc'
10
9
  CLOBBER.include '**/*.log'
11
10
  CLOBBER.include '**/Makefile'
12
11
  CLOBBER.include '**/extconf.h'
13
12
 
13
+ # Not available for really old rubies, but that's ok.
14
+ begin
15
+ require 'pry'
16
+ rescue LoadError
17
+ puts "Failed to load pry."
18
+ end
19
+
20
+ # Load support ruby and rake files (in this order)
21
+ Dir.glob('tasks/*.rb').each { |r| load r}
22
+ Dir.glob('tasks/*.rake').each { |r| load r}
23
+
24
+ desc 'Print Ruby major version (ie "2_5")'
25
+ task :ruby_version do
26
+ print current_ruby_major
27
+ end
28
+
14
29
  def announce(msg='')
15
30
  $stderr.puts msg
16
31
  end
@@ -39,40 +54,31 @@ end
39
54
  make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
40
55
  MAKECMD = ENV['MAKE_CMD'] || make_program
41
56
  MAKEOPTS = ENV['MAKE_OPTS'] || ''
42
-
43
- CURB_SO = "ext/curb_core.#{Config::MAKEFILE_CONFIG['DLEXT']}"
57
+ CURB_SO = "ext/curb_core.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
44
58
 
45
59
  file 'ext/Makefile' => 'ext/extconf.rb' do
46
- Dir.chdir('ext') do
47
- ruby "extconf.rb #{ENV['EXTCONF_OPTS']}"
48
- end
60
+ shell(['ruby', 'extconf.rb', ENV['EXTCONF_OPTS'].to_s],
61
+ { :live_stdout => STDOUT , :cwd => "#{Dir.pwd}/ext" }
62
+ ).error!
49
63
  end
50
64
 
51
65
  def make(target = '')
52
- Dir.chdir('ext') do
53
- pid = system("#{MAKECMD} #{MAKEOPTS} #{target}")
54
- $?.exitstatus
55
- end
66
+ shell(["#{MAKECMD}", "#{MAKEOPTS}", "#{target}"].reject(&:empty?),
67
+ { :live_stdout => STDOUT, :cwd => "#{Dir.pwd}/ext" }
68
+ ).error!
56
69
  end
57
70
 
58
71
  # Let make handle dependencies between c/o/so - we'll just run it.
59
72
  file CURB_SO => (['ext/Makefile'] + Dir['ext/*.c'] + Dir['ext/*.h']) do
60
- m = make
61
- fail "Make failed (status #{m})" unless m == 0
73
+ make
62
74
  end
63
75
 
64
76
  desc "Compile the shared object"
65
77
  task :compile => [CURB_SO]
66
78
 
67
- desc "Create the markdown file"
68
- task :markdown do
69
- cp "README", "README.markdown"
70
- end
71
-
72
79
  desc "Install to your site_ruby directory"
73
- task :install => :alltests do
74
- m = make 'install'
75
- fail "Make install failed (status #{m})" unless m == 0
80
+ task :install do
81
+ make 'install'
76
82
  end
77
83
 
78
84
  # Test Tasks ---------------------------------------------------------
@@ -90,12 +96,12 @@ if ENV['RELTEST']
90
96
  else
91
97
  task :alltests => [:unittests, :bugtests]
92
98
  end
93
-
99
+
94
100
  Rake::TestTask.new(:unittests) do |t|
95
101
  t.test_files = FileList['tests/tc_*.rb']
96
102
  t.verbose = false
97
103
  end
98
-
104
+
99
105
  Rake::TestTask.new(:bugtests) do |t|
100
106
  t.test_files = FileList['tests/bug_*.rb']
101
107
  t.verbose = false
@@ -137,6 +143,12 @@ end
137
143
 
138
144
  desc "Publish the RDoc documentation to project web site"
139
145
  task :doc_upload => [ :doc ] do
146
+ begin
147
+ require 'rdoc/task'
148
+ rescue LoadError => e
149
+ require 'rake/rdoctask'
150
+ end
151
+
140
152
  if ENV['RELTEST']
141
153
  announce "Release Task Testing, skipping doc upload"
142
154
  else
@@ -167,13 +179,13 @@ else
167
179
 
168
180
  desc 'Build gem'
169
181
  task :package => :gemspec do
170
- require 'rubygems/specification'
182
+ require 'rubygems/package'
171
183
  spec_source = File.read File.join(File.dirname(__FILE__),'curb.gemspec')
172
184
  spec = nil
173
185
  # see: http://gist.github.com/16215
174
- Thread.new { spec = eval("$SAFE = 3\n#{spec_source}") }.join
186
+ Thread.new { spec = eval("#{spec_source}") }.join
175
187
  spec.validate
176
- Gem::Builder.new(spec).build
188
+ Gem::Package.build(spec)
177
189
  end
178
190
 
179
191
  task :static do
data/ext/banned.h ADDED
@@ -0,0 +1,32 @@
1
+ #ifndef BANNED_H
2
+ #define BANNED_H
3
+
4
+ /*
5
+ * This header lists functions that have been banned from our code base,
6
+ * because they're too easy to misuse (and even if used correctly,
7
+ * complicate audits). Including this header turns them into compile-time
8
+ * errors.
9
+ */
10
+
11
+ #define BANNED(func) sorry_##func##_is_a_banned_function
12
+
13
+ #undef strcpy
14
+ #define strcpy(x,y) BANNED(strcpy)
15
+ #undef strcat
16
+ #define strcat(x,y) BANNED(strcat)
17
+ #undef strncpy
18
+ #define strncpy(x,y,n) BANNED(strncpy)
19
+ #undef strncat
20
+ #define strncat(x,y,n) BANNED(strncat)
21
+
22
+ #undef sprintf
23
+ #undef vsprintf
24
+ #ifdef HAVE_VARIADIC_MACROS
25
+ #define sprintf(...) BANNED(sprintf)
26
+ #define vsprintf(...) BANNED(vsprintf)
27
+ #else
28
+ #define sprintf(buf,fmt,arg) BANNED(sprintf)
29
+ #define vsprintf(buf,fmt,arg) BANNED(sprintf)
30
+ #endif
31
+
32
+ #endif /* BANNED_H */