tmm1-em-http-request 0.1.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/.autotest +1 -0
- data/LICENSE +58 -0
- data/README +36 -0
- data/Rakefile +72 -0
- data/ext/buffer/em_buffer.c +625 -0
- data/ext/buffer/extconf.rb +53 -0
- data/ext/http11_client/ext_help.h +14 -0
- data/ext/http11_client/extconf.rb +6 -0
- data/ext/http11_client/http11_client.c +302 -0
- data/ext/http11_client/http11_parser.c +403 -0
- data/ext/http11_client/http11_parser.h +48 -0
- data/ext/http11_client/http11_parser.rl +173 -0
- data/lib/em-http/client.rb +404 -0
- data/lib/em-http/multi.rb +51 -0
- data/lib/em-http/request.rb +63 -0
- data/lib/em-http.rb +16 -0
- data/test/helper.rb +5 -0
- data/test/stallion.rb +123 -0
- data/test/test_multi.rb +34 -0
- data/test/test_request.rb +179 -0
- metadata +82 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'autotest/redgreen'
|
data/LICENSE
ADDED
@@ -0,0 +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
|
+
|
data/README
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
EventMachine based HTTP Request interface. Supports streaming response processing / based on Zed Shaw's Ragel HTTP parser.
|
2
|
+
- Borrows a lot of good concepts from Rev's HttpClient, Curb, and other libraries.
|
3
|
+
- Offers support for single or parallel request queries & via deferred callbacks
|
4
|
+
|
5
|
+
Simple client example:
|
6
|
+
--------
|
7
|
+
|
8
|
+
EventMachine.run {
|
9
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}
|
10
|
+
|
11
|
+
http.callback {
|
12
|
+
p http.response_header.status
|
13
|
+
p http.response_header
|
14
|
+
p http.response
|
15
|
+
|
16
|
+
EventMachine.stop
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
Multi request example:
|
21
|
+
----------
|
22
|
+
|
23
|
+
EventMachine.run {
|
24
|
+
multi = EventMachine::MultiRequest.new
|
25
|
+
|
26
|
+
# add multiple requests to the multi-handler
|
27
|
+
multi.add(EventMachine::HttpRequest.new('http://www.google.com/').get)
|
28
|
+
multi.add(EventMachine::HttpRequest.new('http://www.yahoo.com/').get)
|
29
|
+
|
30
|
+
multi.callback {
|
31
|
+
p multi.responses[:succeeded]
|
32
|
+
p multi.responses[:failed]
|
33
|
+
|
34
|
+
EventMachine.stop
|
35
|
+
}
|
36
|
+
}
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'fileutils'
|
6
|
+
include FileUtils
|
7
|
+
|
8
|
+
# Default Rake task is compile
|
9
|
+
task :default => :compile
|
10
|
+
|
11
|
+
# RDoc
|
12
|
+
Rake::RDocTask.new(:rdoc) do |task|
|
13
|
+
task.rdoc_dir = 'doc'
|
14
|
+
task.title = 'EventMachine::HttpRequest'
|
15
|
+
task.options = %w(--title HttpRequest --main README --line-numbers)
|
16
|
+
task.rdoc_files.include(['lib/**/*.rb'])
|
17
|
+
task.rdoc_files.include(['README', 'LICENSE'])
|
18
|
+
end
|
19
|
+
|
20
|
+
# Rebuild parser Ragel
|
21
|
+
task :ragel do
|
22
|
+
Dir.chdir "ext/http11_client" do
|
23
|
+
target = "http11_parser.c"
|
24
|
+
File.unlink target if File.exist? target
|
25
|
+
sh "ragel http11_parser.rl | rlgen-cd -G2 -o #{target}"
|
26
|
+
raise "Failed to build C source" unless File.exist? target
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def make(makedir)
|
31
|
+
Dir.chdir(makedir) { sh 'make' }
|
32
|
+
end
|
33
|
+
|
34
|
+
def extconf(dir)
|
35
|
+
Dir.chdir(dir) { ruby "extconf.rb" }
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_extension(dir, extension)
|
39
|
+
ext = "ext/#{dir}"
|
40
|
+
ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
|
41
|
+
ext_files = FileList[
|
42
|
+
"#{ext}/*.c",
|
43
|
+
"#{ext}/*.h",
|
44
|
+
"#{ext}/extconf.rb",
|
45
|
+
"#{ext}/Makefile",
|
46
|
+
"lib"
|
47
|
+
]
|
48
|
+
|
49
|
+
task "lib" do
|
50
|
+
directory "lib"
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Builds just the #{extension} extension"
|
54
|
+
task extension.to_sym => ["#{ext}/Makefile", ext_so ]
|
55
|
+
|
56
|
+
file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
|
57
|
+
extconf "#{ext}"
|
58
|
+
end
|
59
|
+
|
60
|
+
file ext_so => ext_files do
|
61
|
+
make "#{ext}"
|
62
|
+
cp ext_so, "lib"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
setup_extension("buffer", "em_buffer")
|
67
|
+
setup_extension("http11_client", "http11_client")
|
68
|
+
|
69
|
+
task :compile => [:em_buffer, :http11_client]
|
70
|
+
|
71
|
+
CLEAN.include ['build/*', '**/*.o', '**/*.so', '**/*.a', '**/*.log', 'pkg']
|
72
|
+
CLEAN.include ['ext/buffer/Makefile', 'lib/em_buffer.*', 'lib/http11_client.*']
|