mockingbird 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +13 -0
- data/examples/gzip.rb +22 -0
- data/examples/overview.rb +2 -2
- data/examples/reconnects.rb +4 -4
- data/lib/mockingbird/commands.rb +1 -1
- data/lib/mockingbird/encoders.rb +24 -0
- data/lib/mockingbird/server.rb +28 -18
- data/lib/mockingbird/version.rb +1 -1
- metadata +6 -2
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
0.2.0
|
2
|
+
=====
|
3
|
+
* Fix chunked encoding bug. Scripts that used to rely on "\r\n" being
|
4
|
+
automatically appended to each send call need to be updated to manually add
|
5
|
+
"\r\n" (or whatever line ending) as appropriate.
|
6
|
+
|
7
|
+
0.1.1
|
8
|
+
=====
|
9
|
+
* Add :quiet flag to silence puts during tests (thanks @rud)
|
10
|
+
|
11
|
+
0.1.0
|
12
|
+
=====
|
13
|
+
* Initial release
|
data/examples/gzip.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
require 'mockingbird'
|
5
|
+
require 'gzip'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
Mockingbird.setup(:port=>8080) do
|
9
|
+
|
10
|
+
headers(
|
11
|
+
"Transfer-Encoding"=>"chunked",
|
12
|
+
"Content-Encoding"=>"gzip"
|
13
|
+
)
|
14
|
+
|
15
|
+
send %Q({"foo":"bar"}\r\n)
|
16
|
+
wait 0.5
|
17
|
+
5.times do |n|
|
18
|
+
send %Q({"foo":"bar#{n}"}\r\n)
|
19
|
+
end
|
20
|
+
pipe "#{File.dirname(__FILE__)}/overview_output.txt", :wait=>1
|
21
|
+
close
|
22
|
+
end
|
data/examples/overview.rb
CHANGED
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
|
4
4
|
require 'mockingbird'
|
5
5
|
|
6
6
|
Mockingbird.setup(:port=>8080) do
|
7
|
-
send
|
7
|
+
send %Q({"foo":"bar"}\r\n)
|
8
8
|
wait 0.5
|
9
9
|
5.times do |n|
|
10
|
-
send %Q({"foo":"bar#{n}"})
|
10
|
+
send %Q({"foo":"bar#{n}"}\r\n)
|
11
11
|
end
|
12
12
|
pipe "#{File.dirname(__FILE__)}/overview_output.txt", :wait=>1
|
13
13
|
close
|
data/examples/reconnects.rb
CHANGED
@@ -9,15 +9,15 @@ Mockingbird.setup(:port=>8080) do
|
|
9
9
|
on_connection(1) do
|
10
10
|
disconnect!
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
on_connection(2..5) do
|
14
14
|
wait(0.5)
|
15
15
|
close
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
on_connection('*') do
|
19
|
-
|
20
|
-
send
|
19
|
+
10.times do |i|
|
20
|
+
send %Q({"foo":"bar#{i}"}\r\n)
|
21
21
|
end
|
22
22
|
close
|
23
23
|
end
|
data/lib/mockingbird/commands.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mockingbird
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
def IdentityEncoder
|
5
|
+
def start
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def encode(content)
|
10
|
+
content
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def GzipEncoder
|
15
|
+
|
16
|
+
def start
|
17
|
+
@gzw = Zlib::GzipWriter.new
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/mockingbird/server.rb
CHANGED
@@ -15,9 +15,9 @@ module Mockingbird
|
|
15
15
|
# recommended that you use the simpler convenience interface defined on
|
16
16
|
# the Mockingbird module.
|
17
17
|
module Server
|
18
|
-
|
18
|
+
|
19
19
|
class << self
|
20
|
-
|
20
|
+
|
21
21
|
def start!(opts={})
|
22
22
|
opts = {:host=>'0.0.0.0',:port=>8080}.merge(opts)
|
23
23
|
host = opts[:host]
|
@@ -27,57 +27,67 @@ module Mockingbird
|
|
27
27
|
EventMachine::start_server host, port, self
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def configure(&block)
|
32
32
|
@script = Script.new(&block)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def script
|
36
36
|
@script
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def new_connection_id
|
40
40
|
@connection_id ||= 0
|
41
41
|
@connection_id += 1
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def receive_data(data)
|
47
47
|
conn_id = new_connection_id
|
48
48
|
runner = ScriptRunner.new(self,script.for_connection(conn_id))
|
49
49
|
runner.run
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def new_connection_id
|
53
53
|
Mockingbird::Server.new_connection_id
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def script
|
57
57
|
Mockingbird::Server.script
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def send_status(code=200,text="OK")
|
61
61
|
send_data "HTTP/1.1 #{code} #{text}\r\n"
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def send_header(name,value)
|
65
65
|
send_data "#{name}: #{value}\r\n"
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def start_body
|
69
69
|
send_data "\r\n"
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def send_chunk(chunk)
|
73
|
-
|
74
|
-
send_data "#{
|
75
|
-
send_data "#{
|
73
|
+
len = chunk_length(chunk)
|
74
|
+
send_data "#{len.to_s(16)}\r\n"
|
75
|
+
send_data "#{chunk}\r\n"
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def send_terminal_chunk
|
79
79
|
send_data "0\r\n\r\n"
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
|
+
private
|
83
|
+
def chunk_length(chunk)
|
84
|
+
# Be friendly to 1.8 and 1.9. In 1.9, length is the char length, not
|
85
|
+
# the byte length
|
86
|
+
if chunk.respond_to?(:bytesize)
|
87
|
+
chunk.bytesize
|
88
|
+
else
|
89
|
+
chunk.length
|
90
|
+
end
|
91
|
+
end
|
82
92
|
end
|
83
93
|
end
|
data/lib/mockingbird/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mockingbird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Hayes Davis
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-20 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -33,21 +33,25 @@ extensions: []
|
|
33
33
|
extra_rdoc_files:
|
34
34
|
- LICENSE
|
35
35
|
- README.md
|
36
|
+
- CHANGELOG.md
|
36
37
|
files:
|
37
38
|
- README.md
|
38
39
|
- lib/mockingbird/commands.rb
|
39
40
|
- lib/mockingbird/connection_script.rb
|
41
|
+
- lib/mockingbird/encoders.rb
|
40
42
|
- lib/mockingbird/script.rb
|
41
43
|
- lib/mockingbird/script_runner.rb
|
42
44
|
- lib/mockingbird/server.rb
|
43
45
|
- lib/mockingbird/version.rb
|
44
46
|
- lib/mockingbird.rb
|
45
47
|
- examples/examples.md
|
48
|
+
- examples/gzip.rb
|
46
49
|
- examples/overview.rb
|
47
50
|
- examples/overview_output.txt
|
48
51
|
- examples/reconnects.rb
|
49
52
|
- examples/status_and_headers.rb
|
50
53
|
- LICENSE
|
54
|
+
- CHANGELOG.md
|
51
55
|
has_rdoc: true
|
52
56
|
homepage: http://github.com/hayesdavis/mockingbird
|
53
57
|
licenses: []
|