brianmario-streamly 0.1.2 → 0.1.3
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/CHANGELOG.md +4 -1
- data/README.rdoc +56 -6
- data/VERSION.yml +1 -1
- data/benchmark/basic_request.rb +4 -4
- data/benchmark/streaming_json_request.rb +8 -6
- data/ext/streamly.c +15 -15
- data/lib/streamly.rb +1 -1
- data/streamly.gemspec +5 -2
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.3 (August 19th, 2009)
|
4
|
+
* Fixed a bug where a username or password was specified, but not both
|
5
|
+
|
3
6
|
## 0.1.2 (July 28th, 2009)
|
4
|
-
*
|
7
|
+
* removing call to set CURLOPT_USERPWD to NULL as it would crash in linux
|
5
8
|
|
6
9
|
## 0.1.1 (July 27th, 2009)
|
7
10
|
* Version bump for Github's gem builder
|
data/README.rdoc
CHANGED
@@ -14,26 +14,76 @@ Install it like any other gem hosted at the Githubs like so:
|
|
14
14
|
|
15
15
|
== Example of use
|
16
16
|
|
17
|
+
=== A basic HEAD request
|
18
|
+
|
19
|
+
Streamly.head('www.somehost.com')
|
20
|
+
|
21
|
+
Or streaming
|
22
|
+
|
23
|
+
Streamly.head('www.somehost.com') do |header_chunk|
|
24
|
+
# do something with header_chunk
|
25
|
+
end
|
26
|
+
|
27
|
+
You can also pass a Hash of headers
|
28
|
+
|
29
|
+
Streamly.head('www.somehost.com', {"User-Agent" => "all your base are belong to us"})
|
30
|
+
|
17
31
|
=== A basic GET request
|
18
32
|
|
19
33
|
Streamly.get('www.somehost.com')
|
20
34
|
|
21
|
-
|
35
|
+
Or streaming
|
22
36
|
|
23
|
-
Streamly.get('www.somehost.com') do |
|
24
|
-
# do something with
|
37
|
+
Streamly.get('www.somehost.com') do |body_chunk|
|
38
|
+
# do something with body_chunk
|
25
39
|
end
|
26
40
|
|
41
|
+
You can also pass a Hash of headers
|
42
|
+
|
43
|
+
Streamly.get('www.somehost.com', {"User-Agent" => "all your base are belong to us"})
|
44
|
+
|
27
45
|
=== A basic POST request
|
28
46
|
|
29
47
|
Streamly.post('www.somehost.com', 'blah=foo')
|
30
48
|
|
31
|
-
|
49
|
+
Or streaming
|
32
50
|
|
33
|
-
Streamly.post('www.somehost.com', 'blah=foo') do |
|
34
|
-
# do something with
|
51
|
+
Streamly.post('www.somehost.com', 'blah=foo') do |body_chunk|
|
52
|
+
# do something with body_chunk
|
35
53
|
end
|
36
54
|
|
55
|
+
You can also pass a Hash of headers
|
56
|
+
|
57
|
+
Streamly.post('www.somehost.com', 'blah=foo', {"User-Agent" => "all your base are belong to us"})
|
58
|
+
|
59
|
+
=== A basic PUT request
|
60
|
+
|
61
|
+
Streamly.put('www.somehost.com', 'blah=foo')
|
62
|
+
|
63
|
+
Or streaming
|
64
|
+
|
65
|
+
Streamly.put('www.somehost.com', 'blah=foo') do |body_chunk|
|
66
|
+
# do something with body_chunk
|
67
|
+
end
|
68
|
+
|
69
|
+
You can also pass a Hash of headers
|
70
|
+
|
71
|
+
Streamly.put('www.somehost.com', 'blah=foo', {"User-Agent" => "all your base are belong to us"})
|
72
|
+
|
73
|
+
=== A basic DELETE request
|
74
|
+
|
75
|
+
Streamly.delete('www.somehost.com')
|
76
|
+
|
77
|
+
Or streaming
|
78
|
+
|
79
|
+
Streamly.delete('www.somehost.com') do |body_chunk|
|
80
|
+
# do something with body_chunk
|
81
|
+
end
|
82
|
+
|
83
|
+
You can also pass a Hash of headers
|
84
|
+
|
85
|
+
Streamly.delete('www.somehost.com', {"User-Agent" => "all your base are belong to us"})
|
86
|
+
|
37
87
|
== Benchmarks
|
38
88
|
|
39
89
|
Fetching 2,405,005 bytes of JSON from a local lighttpd server
|
data/VERSION.yml
CHANGED
data/benchmark/basic_request.rb
CHANGED
@@ -10,17 +10,17 @@ require 'benchmark'
|
|
10
10
|
url = ARGV[0]
|
11
11
|
|
12
12
|
Benchmark.bm do |x|
|
13
|
-
puts "
|
13
|
+
puts "Streamly"
|
14
14
|
x.report do
|
15
15
|
(ARGV[1] || 1).to_i.times do
|
16
|
-
|
16
|
+
Streamly.get(url)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
puts "
|
20
|
+
puts "Shell out to curl"
|
21
21
|
x.report do
|
22
22
|
(ARGV[1] || 1).to_i.times do
|
23
|
-
|
23
|
+
`curl -s --compressed #{url}`
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -11,27 +11,29 @@ require 'benchmark'
|
|
11
11
|
url = ARGV[0]
|
12
12
|
|
13
13
|
Benchmark.bm do |x|
|
14
|
-
puts "
|
14
|
+
puts "Streamly"
|
15
15
|
parser = Yajl::Parser.new
|
16
|
+
parser.on_parse_complete = lambda {|obj| }
|
16
17
|
x.report do
|
17
18
|
(ARGV[1] || 1).to_i.times do
|
18
|
-
|
19
|
+
Streamly.get(url) do |chunk|
|
20
|
+
parser << chunk
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
|
-
puts "
|
25
|
+
puts "Shell out to curl"
|
23
26
|
parser = Yajl::Parser.new
|
24
27
|
parser.on_parse_complete = lambda {|obj| }
|
25
28
|
x.report do
|
26
29
|
(ARGV[1] || 1).to_i.times do
|
27
|
-
|
28
|
-
parser << chunk
|
29
|
-
end
|
30
|
+
parser.parse `curl -s --compressed #{url}`
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
puts "rest-client"
|
34
35
|
parser = Yajl::Parser.new
|
36
|
+
parser.on_parse_complete = lambda {|obj| }
|
35
37
|
x.report do
|
36
38
|
(ARGV[1] || 1).to_i.times do
|
37
39
|
parser.parse RestClient.get(url, {"Accept-Encoding" => "identity, deflate, gzip"})
|
data/ext/streamly.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// static size_t
|
1
|
+
// static size_t upload_data_handler(char * stream, size_t size, size_t nmemb, VALUE upload_stream) {
|
2
2
|
// size_t result = 0;
|
3
3
|
//
|
4
4
|
// // TODO
|
@@ -62,17 +62,13 @@ void streamly_instance_free(struct curl_instance * instance) {
|
|
62
62
|
static VALUE each_http_header(VALUE header, VALUE self) {
|
63
63
|
struct curl_instance * instance;
|
64
64
|
GetInstance(self, instance);
|
65
|
-
VALUE
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
header_str = rb_str_plus(name, rb_str_new2(": "));
|
71
|
-
header_str = rb_str_plus(header_str, value);
|
65
|
+
VALUE header_str = rb_str_new2("");
|
66
|
+
|
67
|
+
rb_str_buf_cat(header_str, RSTRING_PTR(rb_ary_entry(header, 0)), RSTRING_LEN(rb_ary_entry(header, 0)));
|
68
|
+
rb_str_buf_cat(header_str, ": ", 2);
|
69
|
+
rb_str_buf_cat(header_str, RSTRING_PTR(rb_ary_entry(header, 1)), RSTRING_LEN(rb_ary_entry(header, 1)));
|
72
70
|
|
73
71
|
instance->request_headers = curl_slist_append(instance->request_headers, RSTRING_PTR(header_str));
|
74
|
-
rb_gc_mark(name);
|
75
|
-
rb_gc_mark(value);
|
76
72
|
rb_gc_mark(header_str);
|
77
73
|
return Qnil;
|
78
74
|
}
|
@@ -230,7 +226,7 @@ VALUE rb_streamly_init(int argc, VALUE * argv, VALUE self) {
|
|
230
226
|
// curl_easy_setopt(instance->handle, CURLOPT_HTTPPOST, 1);
|
231
227
|
|
232
228
|
// TODO: get streaming upload working
|
233
|
-
// curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &
|
229
|
+
// curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &upload_data_handler);
|
234
230
|
// curl_easy_setopt(instance->handle, CURLOPT_READDATA, &instance->upload_stream);
|
235
231
|
// curl_easy_setopt(instance->handle, CURLOPT_INFILESIZE, len);
|
236
232
|
} else if (instance->request_method == sym_put) {
|
@@ -240,7 +236,7 @@ VALUE rb_streamly_init(int argc, VALUE * argv, VALUE self) {
|
|
240
236
|
|
241
237
|
// TODO: get streaming upload working
|
242
238
|
// curl_easy_setopt(instance->handle, CURLOPT_UPLOAD, 1);
|
243
|
-
// curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &
|
239
|
+
// curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &upload_data_handler);
|
244
240
|
// curl_easy_setopt(instance->handle, CURLOPT_READDATA, &instance->upload_stream);
|
245
241
|
// curl_easy_setopt(instance->handle, CURLOPT_INFILESIZE, len);
|
246
242
|
} else if (instance->request_method == sym_delete) {
|
@@ -263,12 +259,16 @@ VALUE rb_streamly_init(int argc, VALUE * argv, VALUE self) {
|
|
263
259
|
curl_easy_setopt(instance->handle, CURLOPT_WRITEDATA, instance->response_body_handler);
|
264
260
|
}
|
265
261
|
|
266
|
-
|
262
|
+
curl_easy_setopt(instance, CURLOPT_USERPWD, NULL);
|
267
263
|
if (!NIL_P(username) || !NIL_P(password)) {
|
268
264
|
credentials = rb_str_new2("");
|
269
|
-
|
265
|
+
if (!NIL_P(username)) {
|
266
|
+
rb_str_buf_cat(credentials, RSTRING_PTR(username), RSTRING_LEN(username));
|
267
|
+
}
|
270
268
|
rb_str_buf_cat(credentials, credential_sep, 1);
|
271
|
-
|
269
|
+
if (!NIL_P(password)) {
|
270
|
+
rb_str_buf_cat(credentials, RSTRING_PTR(password), RSTRING_LEN(password));
|
271
|
+
}
|
272
272
|
curl_easy_setopt(instance->handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
|
273
273
|
curl_easy_setopt(instance->handle, CURLOPT_USERPWD, RSTRING_PTR(credentials));
|
274
274
|
rb_gc_mark(credentials);
|
data/lib/streamly.rb
CHANGED
data/streamly.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{streamly}
|
5
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Brian Lopez"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-08-19}
|
10
13
|
s.email = %q{seniorlopez@gmail.com}
|
11
14
|
s.extensions = ["ext/extconf.rb"]
|
12
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brianmario-streamly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Lopez
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|