curb 0.8.5 → 0.9.11

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: ecd73a0ad8d98960321b8d523e25bad95ff25e8900e8acb187051ca40c7a1cba
4
+ data.tar.gz: c154996d92946fe83fa12d695b073d5026e4a55e92efd177bfad021461f2b313
5
+ SHA512:
6
+ metadata.gz: 48854a4f0d77befe0e81b31a3d39e826b2ef65d58d0226b617a355ba8d063ab4998853a8709ae6d2e3c4629c09ff987099398a1c884b76d95dcf956d941fc660
7
+ data.tar.gz: 3291675a74eb40f42d936bb65689da7d5f295e038ed019482d2cf115ba878232ce4e40aeb125d0fe786b5e82428320938ff3c75592a5c54a2d51fbe8589a0931
data/README.markdown ADDED
@@ -0,0 +1,277 @@
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
+ $ sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev
71
+
72
+ On RedHat:
73
+
74
+ $ sudo yum install ruby-devel libcurl-devel openssl-devel
75
+
76
+ Curb has fairly extensive RDoc comments in the source. You can build the
77
+ documentation with:
78
+
79
+ $ rake doc
80
+
81
+ ## Usage & examples
82
+
83
+ Curb provides two classes:
84
+
85
+ * `Curl::Easy` - simple API, for day-to-day tasks.
86
+ * `Curl::Multi` - more advanced API, for operating on multiple URLs simultaneously.
87
+
88
+ To use either, you will need to require the curb gem:
89
+
90
+ ```ruby
91
+ require 'curb'
92
+ ```
93
+
94
+ ### Super simple API (less typing)
95
+
96
+ ```ruby
97
+ http = Curl.get("http://www.google.com/")
98
+ puts http.body_str
99
+
100
+ http = Curl.post("http://www.google.com/", {:foo => "bar"})
101
+ puts http.body_str
102
+
103
+ http = Curl.get("http://www.google.com/") do |http|
104
+ http.headers['Cookie'] = 'foo=1;bar=2'
105
+ end
106
+ puts http.body_str
107
+ ```
108
+
109
+ ### Simple fetch via HTTP:
110
+
111
+ ```ruby
112
+ c = Curl::Easy.perform("http://www.google.co.uk")
113
+ puts c.body_str
114
+ ```
115
+
116
+ Same thing, more manual:
117
+
118
+ ```ruby
119
+ c = Curl::Easy.new("http://www.google.co.uk")
120
+ c.perform
121
+ puts c.body_str
122
+ ```
123
+
124
+ ### Additional config:
125
+
126
+ ```ruby
127
+ Curl::Easy.perform("http://www.google.co.uk") do |curl|
128
+ curl.headers["User-Agent"] = "myapp-0.0"
129
+ curl.verbose = true
130
+ end
131
+ ```
132
+
133
+ Same thing, more manual:
134
+
135
+ ```ruby
136
+ c = Curl::Easy.new("http://www.google.co.uk") do |curl|
137
+ curl.headers["User-Agent"] = "myapp-0.0"
138
+ curl.verbose = true
139
+ end
140
+
141
+ c.perform
142
+ ```
143
+
144
+ ### HTTP basic authentication:
145
+
146
+ ```ruby
147
+ c = Curl::Easy.new("http://github.com/")
148
+ c.http_auth_types = :basic
149
+ c.username = 'foo'
150
+ c.password = 'bar'
151
+ c.perform
152
+ ```
153
+
154
+ ### HTTP "insecure" SSL connections (like curl -k, --insecure) to avoid Curl::Err::SSLCACertificateError:
155
+
156
+ ```ruby
157
+ c = Curl::Easy.new("https://github.com/")
158
+ c.ssl_verify_peer = false
159
+ c.perform
160
+ ```
161
+
162
+ ### Supplying custom handlers:
163
+
164
+ ```ruby
165
+ c = Curl::Easy.new("http://www.google.co.uk")
166
+
167
+ c.on_body { |data| print(data) }
168
+ c.on_header { |data| print(data) }
169
+
170
+ c.perform
171
+ ```
172
+
173
+ ### Reusing Curls:
174
+
175
+ ```ruby
176
+ c = Curl::Easy.new
177
+
178
+ ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
179
+ c.url = url
180
+ c.perform
181
+ c.body_str
182
+ end
183
+ ```
184
+
185
+ ### HTTP POST form:
186
+
187
+ ```ruby
188
+ c = Curl::Easy.http_post("http://my.rails.box/thing/create",
189
+ Curl::PostField.content('thing[name]', 'box'),
190
+ Curl::PostField.content('thing[type]', 'storage'))
191
+ ```
192
+
193
+ ### HTTP POST file upload:
194
+
195
+ ```ruby
196
+ c = Curl::Easy.new("http://my.rails.box/files/upload")
197
+ c.multipart_form_post = true
198
+ c.http_post(Curl::PostField.file('thing[file]', 'myfile.rb'))
199
+ ```
200
+
201
+ ### Using HTTP/2
202
+
203
+ ```ruby
204
+ c = Curl::Easy.new("https://http2.akamai.com")
205
+ c.set(:HTTP_VERSION, Curl::HTTP_2_0)
206
+
207
+ c.perform
208
+ puts (c.body_str.include? "You are using HTTP/2 right now!") ? "HTTP/2" : "HTTP/1.x"
209
+ ```
210
+
211
+ ### Multi Interface (Basic HTTP GET):
212
+
213
+ ```ruby
214
+ # make multiple GET requests
215
+ easy_options = {:follow_location => true}
216
+ # Use Curl::CURLPIPE_MULTIPLEX for HTTP/2 multiplexing
217
+ multi_options = {:pipeline => Curl::CURLPIPE_HTTP1}
218
+
219
+ Curl::Multi.get(['url1','url2','url3','url4','url5'], easy_options, multi_options) do|easy|
220
+ # do something interesting with the easy response
221
+ puts easy.last_effective_url
222
+ end
223
+ ```
224
+
225
+ ### Multi Interface (Basic HTTP POST):
226
+
227
+ ```ruby
228
+ # make multiple POST requests
229
+ easy_options = {:follow_location => true, :multipart_form_post => true}
230
+ multi_options = {:pipeline => Curl::CURLPIPE_HTTP1}
231
+
232
+
233
+ url_fields = [
234
+ { :url => 'url1', :post_fields => {'f1' => 'v1'} },
235
+ { :url => 'url2', :post_fields => {'f1' => 'v1'} },
236
+ { :url => 'url3', :post_fields => {'f1' => 'v1'} }
237
+ ]
238
+
239
+ Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
240
+ # do something interesting with the easy response
241
+ puts easy.last_effective_url
242
+ end
243
+ ```
244
+
245
+ ### Multi Interface (Advanced):
246
+
247
+ ```ruby
248
+ responses = {}
249
+ requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
250
+ m = Curl::Multi.new
251
+ # add a few easy handles
252
+ requests.each do |url|
253
+ responses[url] = ""
254
+ c = Curl::Easy.new(url) do|curl|
255
+ curl.follow_location = true
256
+ curl.on_body{|data| responses[url] << data; data.size }
257
+ curl.on_success {|easy| puts "success, add more easy handles" }
258
+ end
259
+ m.add(c)
260
+ end
261
+
262
+ m.perform do
263
+ puts "idling... can do some work here"
264
+ end
265
+
266
+ requests.each do|url|
267
+ puts responses[url]
268
+ end
269
+ ```
270
+
271
+ ### Easy Callbacks
272
+
273
+ * `on_success` is called when the response code is 2xx
274
+ * `on_redirect` is called when the response code is 3xx
275
+ * `on_missing` is called when the response code is 4xx
276
+ * `on_failure` is called when the response code is 5xx
277
+ * `on_complete` is called in all cases.
data/Rakefile CHANGED
@@ -2,11 +2,6 @@
2
2
  #
3
3
  require 'rake/clean'
4
4
  require 'rake/testtask'
5
- begin
6
- require 'rdoc/task'
7
- rescue LoadError => e
8
- require 'rake/rdoctask'
9
- end
10
5
 
11
6
  CLEAN.include '**/*.o'
12
7
  CLEAN.include "**/*.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
@@ -15,6 +10,22 @@ CLOBBER.include '**/*.log'
15
10
  CLOBBER.include '**/Makefile'
16
11
  CLOBBER.include '**/extconf.h'
17
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
+
18
29
  def announce(msg='')
19
30
  $stderr.puts msg
20
31
  end
@@ -43,12 +54,11 @@ end
43
54
  make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
44
55
  MAKECMD = ENV['MAKE_CMD'] || make_program
45
56
  MAKEOPTS = ENV['MAKE_OPTS'] || ''
46
-
47
57
  CURB_SO = "ext/curb_core.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
48
58
 
49
59
  file 'ext/Makefile' => 'ext/extconf.rb' do
50
60
  Dir.chdir('ext') do
51
- ruby "extconf.rb #{ENV['EXTCONF_OPTS']}"
61
+ shell('ruby', 'extconf.rb', ENV['EXTCONF_OPTS'].to_s, live_stdout: STDOUT)
52
62
  end
53
63
  end
54
64
 
@@ -68,13 +78,8 @@ end
68
78
  desc "Compile the shared object"
69
79
  task :compile => [CURB_SO]
70
80
 
71
- desc "Create the markdown file"
72
- task :markdown do
73
- cp "README", "README.markdown"
74
- end
75
-
76
81
  desc "Install to your site_ruby directory"
77
- task :install => :alltests do
82
+ task :install do
78
83
  m = make 'install'
79
84
  fail "Make install failed (status #{m})" unless m == 0
80
85
  end
@@ -94,12 +99,12 @@ if ENV['RELTEST']
94
99
  else
95
100
  task :alltests => [:unittests, :bugtests]
96
101
  end
97
-
102
+
98
103
  Rake::TestTask.new(:unittests) do |t|
99
104
  t.test_files = FileList['tests/tc_*.rb']
100
105
  t.verbose = false
101
106
  end
102
-
107
+
103
108
  Rake::TestTask.new(:bugtests) do |t|
104
109
  t.test_files = FileList['tests/bug_*.rb']
105
110
  t.verbose = false
@@ -141,6 +146,12 @@ end
141
146
 
142
147
  desc "Publish the RDoc documentation to project web site"
143
148
  task :doc_upload => [ :doc ] do
149
+ begin
150
+ require 'rdoc/task'
151
+ rescue LoadError => e
152
+ require 'rake/rdoctask'
153
+ end
154
+
144
155
  if ENV['RELTEST']
145
156
  announce "Release Task Testing, skipping doc upload"
146
157
  else
@@ -171,13 +182,13 @@ else
171
182
 
172
183
  desc 'Build gem'
173
184
  task :package => :gemspec do
174
- require 'rubygems/specification'
185
+ require 'rubygems/package'
175
186
  spec_source = File.read File.join(File.dirname(__FILE__),'curb.gemspec')
176
187
  spec = nil
177
188
  # see: http://gist.github.com/16215
178
- Thread.new { spec = eval("$SAFE = 3\n#{spec_source}") }.join
189
+ Thread.new { spec = eval("#{spec_source}") }.join
179
190
  spec.validate
180
- Gem::Builder.new(spec).build
191
+ Gem::Package.build(spec)
181
192
  end
182
193
 
183
194
  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 */