em-http-request 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of em-http-request might be problematic. Click here for more details.

data/LICENSE CHANGED
@@ -1,58 +1,58 @@
1
- Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
- You can redistribute it and/or modify it under either the terms of the GPL
3
- (see COPYING.txt file), or the conditions below:
4
-
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
8
-
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
11
-
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) rename any non-standard executables so the names do not conflict
21
- with standard executables, which must also be provided.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or executable
26
- form, provided that you do at least ONE of the following:
27
-
28
- a) distribute the executables and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard executables non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial). But some files in the distribution
42
- are not written by the author, so that they are not under this terms.
43
-
44
- They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
- files under the ./missing directory. See each file for the copying
46
- condition.
47
-
48
- 5. The scripts and library files supplied as input to or produced as
49
- output from the software do not automatically fall under the
50
- copyright of the software, but belong to whomever generated them,
51
- and may be sold commercially, and may be aggregated with this
52
- software.
53
-
54
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
- PURPOSE.
58
-
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the GPL
3
+ (see COPYING.txt file), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict
21
+ with standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
+ files under the ./missing directory. See each file for the copying
46
+ condition.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
58
+
@@ -0,0 +1,157 @@
1
+ EM-HTTP-Request
2
+ ===============
3
+
4
+ Asynchronous HTTP client for Ruby, based on EventMachine runtime.
5
+
6
+ - Ragel HTTP parser for speed & performance
7
+ - Simple interface for single & parallel requests via deferred callbacks
8
+ - Automatic gzip & deflate decoding
9
+ - Basic-Auth & OAuth support
10
+ - Custom timeout support
11
+ - Stream response processing
12
+ - Proxy support (with SSL Tunneling)
13
+ - Auto-follow 3xx redirects with custom max depth
14
+ - Bi-directional communication with web-socket services
15
+ - [Native mocking support](http://wiki.github.com/igrigorik/em-http-request/mocking-httprequest) and through [Webmock](http://github.com/bblimke/webmock)
16
+
17
+ Getting started
18
+ ---------------
19
+
20
+ gem install em-http-request
21
+ irb:0> require 'em-http'
22
+
23
+ Or checkout [screencast / demo](http://everburning.com/news/eventmachine-screencast-em-http-request/) of using EM-HTTP-Request.
24
+
25
+ Libraries & Applications using em-http
26
+ --------------------------------------
27
+
28
+ - [chirpstream](http://github.com/joshbuddy/chirpstream) - EM client for Twitters Chirpstream API
29
+ - [RDaneel](http://github.com/hasmanydevelopers/RDaneel) - Ruby crawler which respects robots.txt
30
+ - [rsolr-async](http://github.com/mwmitchell/rsolr-async) - An asynchronus connection adapter for RSolr
31
+ - [PubSubHubbub](http://github.com/igrigorik/PubSubHubbub) - Asynchronous PubSubHubbub ruby client
32
+ - and many others.. drop me a link if you want yours included!
33
+
34
+ Simple client example
35
+ ---------------------
36
+
37
+ EventMachine.run {
38
+ http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}, :timeout => 10
39
+
40
+ http.callback {
41
+ p http.response_header.status
42
+ p http.response_header
43
+ p http.response
44
+
45
+ EventMachine.stop
46
+ }
47
+ }
48
+
49
+ Multi-request example
50
+ ---------------------
51
+
52
+ Fire and wait for multiple requests to complete via the MultiRequest interface.
53
+
54
+ EventMachine.run {
55
+ multi = EventMachine::MultiRequest.new
56
+
57
+ # add multiple requests to the multi-handler
58
+ multi.add(EventMachine::HttpRequest.new('http://www.google.com/').get)
59
+ multi.add(EventMachine::HttpRequest.new('http://www.yahoo.com/').get)
60
+
61
+ multi.callback {
62
+ p multi.responses[:succeeded]
63
+ p multi.responses[:failed]
64
+
65
+ EventMachine.stop
66
+ }
67
+ }
68
+
69
+ Basic-Auth example
70
+ ------------------
71
+
72
+ Full basic author support. For OAuth, check examples/oauth-tweet.rb file.
73
+
74
+ EventMachine.run {
75
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get :head => {'authorization' => ['user', 'pass']}
76
+
77
+ http.errback { failed }
78
+ http.callback {
79
+ p http.response_header
80
+ EventMachine.stop
81
+ }
82
+ }
83
+
84
+
85
+ POSTing data example
86
+ --------------------
87
+
88
+ EventMachine.run {
89
+ http1 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => {"key1" => 1, "key2" => [2,3]}
90
+ http2 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => "some data"
91
+
92
+ # ...
93
+ }
94
+
95
+ Streaming body processing
96
+ -------------------------
97
+
98
+ Allows you to consume an HTTP stream of content in real-time. Each time a new piece of content is pushed
99
+ to the client, it is passed to the stream callback for you to operate on.
100
+
101
+ EventMachine.run {
102
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get
103
+ http.stream { |chunk| print chunk }
104
+ }
105
+
106
+ Streaming files from disk
107
+ -------------------------
108
+ Allows you to efficiently stream a (large) file from disk via EventMachine's FileStream interface.
109
+
110
+ EventMachine.run {
111
+ http = EventMachine::HttpRequest.new('http://www.website.com/').post :file => 'largefile.txt'
112
+ http.callback { |chunk| puts "Upload finished!" }
113
+ }
114
+
115
+ Proxy example
116
+ -------------
117
+
118
+ Full transparent proxy support with support for SSL tunneling.
119
+
120
+ EventMachine.run {
121
+ http = EventMachine::HttpRequest.new('http://www.website.com/').get :proxy => {
122
+ :host => 'www.myproxy.com',
123
+ :port => 8080,
124
+ :authorization => ['username', 'password'] # authorization is optional
125
+ }
126
+
127
+ Auto-follow 3xx redirects
128
+ -------------------------
129
+
130
+ Specify the max depth of redirects to follow, default is 0.
131
+
132
+ EventMachine.run {
133
+ http = EventMachine::HttpRequest.new('http://www.google.com/').get :redirects => 1
134
+ http.callback { p http.last_effective_url }
135
+ }
136
+
137
+ WebSocket example
138
+ -----------------
139
+
140
+ [Bi-directional communication with WebSockets](http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser/): simply pass in a ws:// resource and the client will negotiate the connection upgrade for you. On successful handshake the callback is invoked, and any incoming messages will be passed to the stream callback. The client can also send data to the server at will by calling the "send" method!
141
+
142
+ EventMachine.run {
143
+ http = EventMachine::HttpRequest.new("ws://yourservice.com/websocket").get :timeout => 0
144
+
145
+ http.errback { puts "oops" }
146
+ http.callback {
147
+ puts "WebSocket connected!"
148
+ http.send("Hello client")
149
+ }
150
+
151
+ http.stream { |msg|
152
+ puts "Recieved: #{msg}"
153
+ http.send "Pong: #{msg}"
154
+ }
155
+
156
+ http.disconnect { puts "oops, dropped connection?" }
157
+ }
data/Rakefile CHANGED
@@ -1,106 +1,110 @@
1
- require 'rake'
2
- require 'rake/clean'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
- require 'fileutils'
6
- include FileUtils
7
-
8
- # copied from EventMachine.
9
- MAKE = ENV['MAKE'] || if RUBY_PLATFORM =~ /mswin/ # mingw uses make.
10
- 'nmake'
11
- else
12
- 'make'
13
- end
14
-
15
- # Default Rake task is compile
16
- task :default => :compile
17
-
18
- # RDoc
19
- Rake::RDocTask.new(:rdoc) do |task|
20
- task.rdoc_dir = 'doc'
21
- task.title = 'EventMachine::HttpRequest'
22
- task.options = %w(--title HttpRequest --main README --line-numbers)
23
- task.rdoc_files.include(['lib/**/*.rb'])
24
- task.rdoc_files.include(['README', 'LICENSE'])
25
- end
26
-
27
- # Rebuild parser Ragel
28
- task :ragel do
29
- Dir.chdir "ext/http11_client" do
30
- target = "http11_parser.c"
31
- File.unlink target if File.exist? target
32
- sh "ragel http11_parser.rl | rlgen-cd -G2 -o #{target}"
33
- raise "Failed to build C source" unless File.exist? target
34
- end
35
- end
36
-
37
- task :spec do
38
- sh 'spec spec/*_spec.rb'
39
- end
40
-
41
- def make(makedir)
42
- Dir.chdir(makedir) { sh MAKE }
43
- end
44
-
45
- def extconf(dir)
46
- Dir.chdir(dir) { ruby "extconf.rb" }
47
- end
48
-
49
- def setup_extension(dir, extension)
50
- ext = "ext/#{dir}"
51
- ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
52
- ext_files = FileList[
53
- "#{ext}/*.c",
54
- "#{ext}/*.h",
55
- "#{ext}/extconf.rb",
56
- "#{ext}/Makefile",
57
- "lib"
58
- ]
59
-
60
- task "lib" do
61
- directory "lib"
62
- end
63
-
64
- desc "Builds just the #{extension} extension"
65
-
66
- mf = (extension + '_makefile').to_sym
67
-
68
- task mf do |t|
69
- extconf "#{ext}"
70
- end
71
-
72
- task extension.to_sym => [mf] do
73
- make "#{ext}"
74
- cp ext_so, "lib"
75
- end
76
- end
77
-
78
- setup_extension("buffer", "em_buffer")
79
- setup_extension("http11_client", "http11_client")
80
-
81
- task :compile => [:em_buffer, :http11_client]
82
-
83
- CLEAN.include ['build/*', '**/*.o', '**/*.so', '**/*.a', '**/*.log', 'pkg']
84
- CLEAN.include ['ext/buffer/Makefile', 'lib/em_buffer.*', 'lib/http11_client.*']
85
-
86
- begin
87
- require 'jeweler'
88
- Jeweler::Tasks.new do |gemspec|
89
- gemspec.name = "em-http-request"
90
- gemspec.summary = "EventMachine based, async HTTP Request interface"
91
- gemspec.description = gemspec.summary
92
- gemspec.email = "ilya@igvita.com"
93
- gemspec.homepage = "http://github.com/igrigorik/em-http-request"
94
- gemspec.authors = ["Ilya Grigorik"]
95
- gemspec.required_ruby_version = ">= 1.8.6"
96
- gemspec.extensions = ["ext/buffer/extconf.rb" , "ext/http11_client/extconf.rb"]
97
- gemspec.add_dependency('eventmachine', '>= 0.12.9')
98
- gemspec.add_dependency('addressable', '>= 2.0.0')
99
- gemspec.rubyforge_project = "em-http-request"
100
- gemspec.files = FileList[`git ls-files`.split]
101
- end
102
-
103
- Jeweler::GemcutterTasks.new
104
- rescue LoadError
105
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
106
- end
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+ require 'fileutils'
6
+ include FileUtils
7
+
8
+ # copied from EventMachine.
9
+ MAKE = ENV['MAKE'] || if RUBY_PLATFORM =~ /mswin/ # mingw uses make.
10
+ 'nmake'
11
+ else
12
+ 'make'
13
+ end
14
+
15
+ # Default Rake task is compile
16
+ task :default => :compile
17
+
18
+ # RDoc
19
+ Rake::RDocTask.new(:rdoc) do |task|
20
+ task.rdoc_dir = 'doc'
21
+ task.title = 'EventMachine::HttpRequest'
22
+ task.options = %w(--title HttpRequest --main README --line-numbers)
23
+ task.rdoc_files.include(['lib/**/*.rb'])
24
+ task.rdoc_files.include(['README', 'LICENSE'])
25
+ end
26
+
27
+ # Rebuild parser Ragel
28
+ task :ragel do
29
+ Dir.chdir "ext/http11_client" do
30
+ target = "http11_parser.c"
31
+ File.unlink target if File.exist? target
32
+ sh "ragel http11_parser.rl | rlgen-cd -G2 -o #{target}"
33
+ raise "Failed to build C source" unless File.exist? target
34
+ end
35
+ end
36
+
37
+ require 'spec'
38
+ require 'spec/rake/spectask'
39
+ Spec::Rake::SpecTask.new(:spec) do |t|
40
+ t.spec_opts ||= []
41
+ t.spec_opts << "--options" << "spec/spec.opts"
42
+ t.spec_files = FileList['spec/**/*_spec.rb']
43
+ end
44
+
45
+ def make(makedir)
46
+ Dir.chdir(makedir) { sh MAKE }
47
+ end
48
+
49
+ def extconf(dir)
50
+ Dir.chdir(dir) { ruby "extconf.rb" }
51
+ end
52
+
53
+ def setup_extension(dir, extension)
54
+ ext = "ext/#{dir}"
55
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
56
+ ext_files = FileList[
57
+ "#{ext}/*.c",
58
+ "#{ext}/*.h",
59
+ "#{ext}/extconf.rb",
60
+ "#{ext}/Makefile",
61
+ "lib"
62
+ ]
63
+
64
+ task "lib" do
65
+ directory "lib"
66
+ end
67
+
68
+ desc "Builds just the #{extension} extension"
69
+
70
+ mf = (extension + '_makefile').to_sym
71
+
72
+ task mf do |t|
73
+ extconf "#{ext}"
74
+ end
75
+
76
+ task extension.to_sym => [mf] do
77
+ make "#{ext}"
78
+ cp ext_so, "lib"
79
+ end
80
+ end
81
+
82
+ setup_extension("buffer", "em_buffer")
83
+ setup_extension("http11_client", "http11_client")
84
+
85
+ task :compile => [:em_buffer, :http11_client]
86
+
87
+ CLEAN.include ['build/*', '**/*.o', '**/*.so', '**/*.a', '**/*.log', 'pkg']
88
+ CLEAN.include ['ext/buffer/Makefile', 'lib/em_buffer.*', 'lib/http11_client.*']
89
+
90
+ begin
91
+ require 'jeweler'
92
+ Jeweler::Tasks.new do |gemspec|
93
+ gemspec.name = "em-http-request"
94
+ gemspec.summary = "EventMachine based, async HTTP Request interface"
95
+ gemspec.description = gemspec.summary
96
+ gemspec.email = "ilya@igvita.com"
97
+ gemspec.homepage = "http://github.com/igrigorik/em-http-request"
98
+ gemspec.authors = ["Ilya Grigorik"]
99
+ gemspec.required_ruby_version = ">= 1.8.6"
100
+ gemspec.extensions = ["ext/buffer/extconf.rb" , "ext/http11_client/extconf.rb"]
101
+ gemspec.add_dependency('eventmachine', '>= 0.12.9')
102
+ gemspec.add_dependency('addressable', '>= 2.0.0')
103
+ gemspec.rubyforge_project = "em-http-request"
104
+ gemspec.files = FileList[`git ls-files`.split]
105
+ end
106
+
107
+ Jeweler::GemcutterTasks.new
108
+ rescue LoadError
109
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
110
+ end