experella-proxy 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,18 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe ExperellaProxy::BackendServer do
4
4
 
5
- let(:backend) {
6
- ExperellaProxy::BackendServer.new("host", "port", {:concurrency => "2", :name => "name",
7
- :accepts => {"Host" => "experella", :path => "ella"},
8
- :mangle => {"Connection" => "close"}
9
- })
10
- }
11
- let(:min_backend) {
5
+ let(:backend) do
6
+ ExperellaProxy::BackendServer.new("host", "port", :concurrency => "2", :name => "name",
7
+ :accepts => { "Host" => "experella", :path => "ella" },
8
+ :mangle => { "Connection" => "close" }
9
+ )
10
+ end
11
+ let(:min_backend) do
12
12
  ExperellaProxy::BackendServer.new("host", "port")
13
- }
14
- let(:matcher) {
13
+ end
14
+ let(:matcher) do
15
15
  backend.message_matcher
16
- }
16
+ end
17
17
 
18
18
  describe "#new" do
19
19
 
@@ -45,7 +45,7 @@ describe ExperellaProxy::BackendServer do
45
45
  end
46
46
 
47
47
  it "mangle should be nil" do
48
- backend.mangle.should == {:Connection => "close"}
48
+ backend.mangle.should == { :Connection => "close" }
49
49
  min_backend.mangle.should be_nil
50
50
  end
51
51
 
@@ -64,14 +64,12 @@ describe ExperellaProxy::BackendServer do
64
64
 
65
65
  describe "#accept?" do
66
66
 
67
-
68
67
  it "returns false if desired request header missing" do
69
68
  request = ExperellaProxy::Request.new("")
70
69
  request.update_header(:request_url => "/docs")
71
70
  backend.accept?(request).should be_false
72
71
  end
73
72
 
74
-
75
73
  it "returns false if request headers doesn't match the message_matcher" do
76
74
  request = ExperellaProxy::Request.new("")
77
75
  request.update_header(:Host => "experella.com", :request_url => "/docs")
@@ -81,15 +79,15 @@ describe ExperellaProxy::BackendServer do
81
79
  end
82
80
 
83
81
  it "accepts a block as message matcher" do
84
- lambdaBackend = ExperellaProxy::BackendServer.new("host", "port", {:concurrency => "2", :name => "name",
85
- :accepts => lambda { |req|
82
+ lambdaBackend = ExperellaProxy::BackendServer.new("host", "port", :concurrency => "2", :name => "name",
83
+ :accepts => lambda do |req|
86
84
  if req.header[:Host] == "google.com"
87
85
  true
88
86
  else
89
87
  false
90
88
  end
91
- }
92
- })
89
+ end
90
+ )
93
91
  request = ExperellaProxy::Request.new("")
94
92
  request.update_header(:Host => "google.com", :request_url => "/docs")
95
93
  lambdaBackend.accept?(request).should be_true
@@ -106,4 +104,4 @@ describe ExperellaProxy::BackendServer do
106
104
 
107
105
  end
108
106
 
109
- end
107
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ExperellaProxy::Configuration do
4
- let(:config) {
4
+ let(:config) do
5
5
  ExperellaProxy.config
6
- }
6
+ end
7
7
 
8
8
  it "should load a config file" do
9
9
  config.backends.size.should == 4
@@ -17,7 +17,7 @@ describe ExperellaProxy::Configuration do
17
17
  end
18
18
 
19
19
  it "should raise NoConfigError if config filepath doesn't exist" do
20
- lambda { config.read_config_file("/a/non/existing/filepath")
21
- }.should raise_error(ExperellaProxy::Configuration::NoConfigError)
20
+ lambda do config.read_config_file("/a/non/existing/filepath")
21
+ end.should raise_error(ExperellaProxy::Configuration::NoConfigError)
22
22
  end
23
23
  end
@@ -2,13 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe ExperellaProxy::ConnectionManager do
4
4
 
5
- let(:manager) {
5
+ let(:manager) do
6
6
  ExperellaProxy::ConnectionManager.new
7
- }
7
+ end
8
8
 
9
9
  class Testconnection
10
-
11
- def initialize()
10
+ def initialize
12
11
  @request = ExperellaProxy::Request.new(self)
13
12
  end
14
13
 
@@ -41,8 +40,8 @@ describe ExperellaProxy::ConnectionManager do
41
40
  manager.add_backend(ExperellaProxy::BackendServer.new("host", "port"))
42
41
  manager.backend_count.should == 1
43
42
  manager.backend_queue_count.should == 1
44
- manager.backend_available?(Testconnection.new().get_request)
45
- manager.backend_available?(Testconnection.new().get_request)
43
+ manager.backend_available?(Testconnection.new.get_request)
44
+ manager.backend_available?(Testconnection.new.get_request)
46
45
  manager.backend_count.should == 1
47
46
  manager.backend_queue_count.should == 0
48
47
  manager.connection_count.should == 1
@@ -76,8 +75,8 @@ describe ExperellaProxy::ConnectionManager do
76
75
  it "should return a connection if any queued conn matches" do
77
76
  backend = ExperellaProxy::BackendServer.new("host", "port")
78
77
  manager.add_backend(backend)
79
- manager.backend_available?(Testconnection.new().get_request)
80
- manager.backend_available?(Testconnection.new().get_request)
78
+ manager.backend_available?(Testconnection.new.get_request)
79
+ manager.backend_available?(Testconnection.new.get_request)
81
80
  ret = manager.free_backend(backend)
82
81
  ret.should be_an_instance_of Testconnection
83
82
  end
@@ -85,11 +84,11 @@ describe ExperellaProxy::ConnectionManager do
85
84
  it "should return nil and requeue backend if no conn matches" do
86
85
  backend = ExperellaProxy::BackendServer.new("host", "port")
87
86
  manager.add_backend(backend)
88
- manager.backend_available?(Testconnection.new().get_request)
87
+ manager.backend_available?(Testconnection.new.get_request)
89
88
  backend_queue = manager.backend_queue_count
90
89
  workload = backend.workload
91
90
  ret = manager.free_backend(backend)
92
- ret.should == nil
91
+ ret.should.nil?
93
92
  manager.backend_queue_count.should == (backend_queue + 1)
94
93
  backend.workload.should == (workload - 1)
95
94
  end
@@ -101,8 +100,8 @@ describe ExperellaProxy::ConnectionManager do
101
100
  backend = ExperellaProxy::BackendServer.new("host", "port")
102
101
  manager.add_backend(backend)
103
102
  connections = []
104
- connections[1] = Testconnection.new()
105
- connections[2] = Testconnection.new()
103
+ connections[1] = Testconnection.new
104
+ connections[2] = Testconnection.new
106
105
  manager.backend_available?(connections[1].get_request)
107
106
  manager.backend_available?(connections[2].get_request)
108
107
  count_before = manager.connection_count
@@ -113,9 +112,9 @@ describe ExperellaProxy::ConnectionManager do
113
112
 
114
113
  describe "#backend_available?" do
115
114
  before(:each) do
116
- manager.add_backend(ExperellaProxy::BackendServer.new("host", "port", {:concurrency => 3, :accepts => {"Host" => "test"}}))
117
- manager.add_backend(ExperellaProxy::BackendServer.new("host2", "port", {:accepts => {"Host" => "bla"}}))
118
- manager.add_backend(ExperellaProxy::BackendServer.new("host3", "port", {:accepts => {"Host" => "blax"}}))
115
+ manager.add_backend(ExperellaProxy::BackendServer.new("host", "port", :concurrency => 3, :accepts => { "Host" => "test" }))
116
+ manager.add_backend(ExperellaProxy::BackendServer.new("host2", "port", :accepts => { "Host" => "bla" }))
117
+ manager.add_backend(ExperellaProxy::BackendServer.new("host3", "port", :accepts => { "Host" => "blax" }))
119
118
  end
120
119
  it "returns first matching backend and removes it from queue" do
121
120
  conn = Testconnection.new
@@ -156,4 +155,4 @@ describe ExperellaProxy::ConnectionManager do
156
155
 
157
156
  end
158
157
 
159
- end
158
+ end
@@ -22,23 +22,23 @@ describe ExperellaProxy do
22
22
 
23
23
  # static testnames send to spawned experella for simplecov
24
24
  ENV_TESTNAMES = {
25
- "should get response from the echoserver via the proxy" => "response",
26
- "should respond with 404" => "404",
27
- "should respond with 400 on malformed request" => "400",
28
- "should respond with 503" => "503",
29
- "should reuse keep-alive connections" => "keep-alive",
25
+ "should get response from the echoserver via the proxy" => "response",
26
+ "should respond with 404" => "404",
27
+ "should respond with 400 on malformed request" => "400",
28
+ "should respond with 503" => "503",
29
+ "should reuse keep-alive connections" => "keep-alive",
30
30
  "should handle chunked post requests and strip invalid Content-Length" => "chunked-request",
31
- "should rechunk and stream Transfer-Encoding chunked responses" => "chunked-response",
32
- "should timeout inactive connections after config.timeout" => "timeout",
33
- "should handle pipelined requests correctly" => "pipelined",
34
- "should accept requests on all set proxy domains" => "multiproxy",
35
- "should be able to handle post requests" => "post"
31
+ "should rechunk and stream Transfer-Encoding chunked responses" => "chunked-response",
32
+ "should timeout inactive connections after config.timeout" => "timeout",
33
+ "should handle pipelined requests correctly" => "pipelined",
34
+ "should accept requests on all set proxy domains" => "multiproxy",
35
+ "should be able to handle post requests" => "post"
36
36
  }
37
37
 
38
38
  describe "EchoServer" do
39
39
  before :each do
40
40
  @pid = spawn("ruby", "#{echo_server}", "127.0.0.10", "7654")
41
- sleep(0.8) #let the server startup, specs may fail if this is set to low
41
+ sleep(0.8) # let the server startup, specs may fail if this is set to low
42
42
  end
43
43
  after :each do
44
44
  Process.kill('QUIT', @pid)
@@ -46,9 +46,9 @@ describe ExperellaProxy do
46
46
  end
47
47
 
48
48
  it "should get response from the echoserver" do
49
- lambda {
49
+ lambda do
50
50
  EM.run do
51
- http = EventMachine::HttpRequest.new("http://127.0.0.10:7654").get({:connect_timeout => 1})
51
+ http = EventMachine::HttpRequest.new("http://127.0.0.10:7654").get(:connect_timeout => 1)
52
52
  http.errback {
53
53
  EventMachine.stop
54
54
  raise "http request failed"
@@ -58,7 +58,7 @@ describe ExperellaProxy do
58
58
  EventMachine.stop
59
59
  }
60
60
  end
61
- }.should_not raise_error
61
+ end.should_not raise_error
62
62
  end
63
63
  end
64
64
 
@@ -68,9 +68,9 @@ describe ExperellaProxy do
68
68
  ENV["TESTNAME"] = ENV_TESTNAMES[test.example.description]
69
69
  end
70
70
  @pid = spawn("ruby", "#{echo_server}", "127.0.0.10", "7654")
71
- @pid2 = spawn("#{experella_proxy}", "run", "--", "--config=#{File.join(File.dirname(__FILE__),"/../fixtures/test_config.rb")}")
72
- sleep(0.8) #let the server startup, specs may fail if this is set to low
73
- ExperellaProxy.init(:configfile => File.join(File.dirname(__FILE__),"/../fixtures/test_config.rb"))
71
+ @pid2 = spawn("#{experella_proxy}", "run", "--", "--config=#{File.join(File.dirname(__FILE__), "/../fixtures/test_config.rb")}")
72
+ sleep(0.8) # let the server startup, specs may fail if this is set to low
73
+ ExperellaProxy.init(:configfile => File.join(File.dirname(__FILE__), "/../fixtures/test_config.rb"))
74
74
  config.backends.each do |backend|
75
75
  connection_manager.add_backend(ExperellaProxy::BackendServer.new(backend[:host], backend[:port], backend))
76
76
  end
@@ -86,10 +86,10 @@ describe ExperellaProxy do
86
86
  log.info "should get response from the echoserver via the proxy"
87
87
  EM.epoll
88
88
  EM.run do
89
- lambda {
89
+ lambda do
90
90
  EventMachine.add_timer(0.2) do
91
91
  http = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}"
92
- ).get({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
92
+ ).get(:connect_timeout => 1, :head => { "Host" => "experella.com" })
93
93
  http.errback {
94
94
  EventMachine.stop
95
95
  raise "http request failed"
@@ -99,7 +99,7 @@ describe ExperellaProxy do
99
99
  EventMachine.stop
100
100
  }
101
101
  end
102
- }.should_not raise_error
102
+ end.should_not raise_error
103
103
  end
104
104
  end
105
105
 
@@ -107,18 +107,18 @@ describe ExperellaProxy do
107
107
  log.info "should respond with 404"
108
108
  EM.epoll
109
109
  EM.run do
110
- lambda {
110
+ lambda do
111
111
  EventMachine.add_timer(0.2) do
112
112
 
113
113
  multi = EventMachine::MultiRequest.new
114
114
  multi_shuffle = []
115
- multi_shuffle[0] = Proc.new {
115
+ multi_shuffle[0] = proc {
116
116
  multi.add :head, EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}"
117
- ).head({:connect_timeout => 1})
117
+ ).head(:connect_timeout => 1)
118
118
  }
119
- multi_shuffle[1] = Proc.new {
119
+ multi_shuffle[1] = proc {
120
120
  multi.add :get, EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}"
121
- ).get({:connect_timeout => 1})
121
+ ).get(:connect_timeout => 1)
122
122
  }
123
123
  multi_shuffle.shuffle!
124
124
  multi_shuffle.each do |p|
@@ -137,9 +137,8 @@ describe ExperellaProxy do
137
137
  EventMachine.stop
138
138
  end
139
139
 
140
-
141
140
  end
142
- }.should_not raise_error
141
+ end.should_not raise_error
143
142
  end
144
143
  end
145
144
 
@@ -147,11 +146,11 @@ describe ExperellaProxy do
147
146
  log.info "should respond with 400 on malformed request"
148
147
  EM.epoll
149
148
  EM.run do
150
- lambda {
149
+ lambda do
151
150
  EventMachine.add_timer(0.2) do
152
151
  http = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}"
153
- ).post({:connect_timeout => 1, :head => {"Host" => "experella.com", "Transfer-Encoding" => "chunked"},
154
- :body => "9\r\nMalformed\r\na\r\nchunked da\r\n2\rta HERE\r\n0\r\n\r\n"})
152
+ ).post(:connect_timeout => 1, :head => { "Host" => "experella.com", "Transfer-Encoding" => "chunked" },
153
+ :body => "9\r\nMalformed\r\na\r\nchunked da\r\n2\rta HERE\r\n0\r\n\r\n")
155
154
  http.errback {
156
155
  EventMachine.stop
157
156
  raise "http request failed"
@@ -161,7 +160,7 @@ describe ExperellaProxy do
161
160
  EventMachine.stop
162
161
  }
163
162
  end
164
- }.should_not raise_error
163
+ end.should_not raise_error
165
164
  end
166
165
  end
167
166
 
@@ -169,18 +168,18 @@ describe ExperellaProxy do
169
168
  log.info "should respond with 503"
170
169
  EM.epoll
171
170
  EM.run do
172
- lambda {
171
+ lambda do
173
172
  EventMachine.add_timer(0.2) do
174
173
 
175
174
  multi = EventMachine::MultiRequest.new
176
175
  multi_shuffle = []
177
- multi_shuffle[0] = Proc.new {
176
+ multi_shuffle[0] = proc {
178
177
  multi.add :head, EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}/oneroute"
179
- ).head({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
178
+ ).head(:connect_timeout => 1, :head => { "Host" => "experella.com" })
180
179
  }
181
- multi_shuffle[1] = Proc.new {
180
+ multi_shuffle[1] = proc {
182
181
  multi.add :get, EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}/anotherpath"
183
- ).get({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
182
+ ).get(:connect_timeout => 1, :head => { "Host" => "experella.com" })
184
183
  }
185
184
  multi_shuffle.shuffle!
186
185
  multi_shuffle.each do |p|
@@ -199,9 +198,8 @@ describe ExperellaProxy do
199
198
  EventMachine.stop
200
199
  end
201
200
 
202
-
203
201
  end
204
- }.should_not raise_error
202
+ end.should_not raise_error
205
203
  end
206
204
  end
207
205
 
@@ -209,10 +207,10 @@ describe ExperellaProxy do
209
207
  log.info "should reuse keep-alive connections"
210
208
  EM.epoll
211
209
  EM.run do
212
- lambda {
210
+ lambda do
213
211
  EventMachine.add_timer(0.2) do
214
212
  conn = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}")
215
- req1 = conn.get({:connect_timeout => 1, :keepalive => true, :head => {"Host" => "experella.com"}})
213
+ req1 = conn.get(:connect_timeout => 1, :keepalive => true, :head => { "Host" => "experella.com" })
216
214
 
217
215
  req1.errback {
218
216
  EventMachine.stop
@@ -220,14 +218,14 @@ describe ExperellaProxy do
220
218
  }
221
219
  req1.callback {
222
220
  req1.response.should start_with "you sent: "
223
- req2 = conn.get({:path => '/about/', :connect_timeout => 1, :keepalive => true, :head => {"Host" => "experella.com"}})
221
+ req2 = conn.get(:path => '/about/', :connect_timeout => 1, :keepalive => true, :head => { "Host" => "experella.com" })
224
222
  req2.errback {
225
223
  EventMachine.stop
226
224
  raise "http request 2 failed"
227
225
  }
228
226
  req2.callback {
229
227
  req2.response.should start_with "you sent: "
230
- req3 = conn.get({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
228
+ req3 = conn.get(:connect_timeout => 1, :head => { "Host" => "experella.com" })
231
229
  req3.errback {
232
230
  EventMachine.stop
233
231
  raise "http request 3 failed"
@@ -239,7 +237,7 @@ describe ExperellaProxy do
239
237
  }
240
238
  }
241
239
  end
242
- }.should_not raise_error
240
+ end.should_not raise_error
243
241
  end
244
242
  end
245
243
 
@@ -247,7 +245,7 @@ describe ExperellaProxy do
247
245
  log.info "should stream chunked post requests"
248
246
  EM.epoll
249
247
  EM.run do
250
- lambda {
248
+ lambda do
251
249
  EventMachine.add_timer(0.2) do
252
250
  # this will issue a Post Request with Content-Length AND Transfer-Encoding chunked, where the data is
253
251
  # correctly encoded in chunks. The Proxy should therefor strip the Content-Length and forward the data
@@ -265,10 +263,10 @@ describe ExperellaProxy do
265
263
  expected_body = String.new
266
264
  chunks = 20 + rand(20)
267
265
  # all alphanumeric characters
268
- o = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
269
- while chunks > 0 do
270
- #chunksize 10 to 1510 characters
271
- string = (0...(10 + rand(1500))).map { o[rand(o.length)] }.join
266
+ o = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map{ |i| i.to_a }.flatten
267
+ while chunks > 0
268
+ # chunksize 10 to 1510 characters
269
+ string = (0...(10 + rand(1500))).map{ o[rand(o.length)] }.join
272
270
  body << string.size.to_s(16)
273
271
  body << "\r\n"
274
272
  body << string
@@ -279,8 +277,8 @@ describe ExperellaProxy do
279
277
  body << "0\r\n\r\n"
280
278
 
281
279
  http = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}"
282
- ).post({:connect_timeout => 1, :head => {"Host" => "experella.com", "Transfer-Encoding" => "chunked"},
283
- :body => body})
280
+ ).post(:connect_timeout => 1, :head => { "Host" => "experella.com", "Transfer-Encoding" => "chunked" },
281
+ :body => body)
284
282
  http.errback {
285
283
  EventMachine.stop
286
284
  raise "http request failed"
@@ -309,7 +307,7 @@ describe ExperellaProxy do
309
307
  EventMachine.stop
310
308
  }
311
309
  end
312
- }.should_not raise_error
310
+ end.should_not raise_error
313
311
  end
314
312
 
315
313
  end
@@ -319,17 +317,17 @@ describe ExperellaProxy do
319
317
  log.info "should rechunk and stream Transfer-Encoding chunked responses"
320
318
  EM.epoll
321
319
  EM.run do
322
- lambda {
320
+ lambda do
323
321
  EventMachine.add_timer(0.2) do
324
322
  http = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}/chunked"
325
- ).get({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
323
+ ).get(:connect_timeout => 1, :head => { "Host" => "experella.com" })
326
324
  http.errback {
327
325
  EventMachine.stop
328
326
  raise "http request failed"
329
327
  }
330
328
  received_chunks = ""
331
329
  http.stream { |chunk|
332
- received_chunks << chunk
330
+ received_chunks << chunk
333
331
  }
334
332
  http.callback {
335
333
  true.should be_true
@@ -338,7 +336,7 @@ describe ExperellaProxy do
338
336
  EventMachine.stop
339
337
  }
340
338
  end
341
- }.should_not raise_error
339
+ end.should_not raise_error
342
340
  end
343
341
 
344
342
  end
@@ -348,14 +346,14 @@ describe ExperellaProxy do
348
346
  EM.epoll
349
347
  EM.run do
350
348
 
351
- lambda {
349
+ lambda do
352
350
  EventMachine.add_timer(0.2) do
353
351
  time = Time.now
354
352
  conn = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}")
355
- req1 = conn.get({:connect_timeout => 1, :inactivity_timeout => config.timeout + 5,
356
- :keepalive => true, :head => {"Host" => "experella.com"}})
353
+ req1 = conn.get(:connect_timeout => 1, :inactivity_timeout => config.timeout + 5,
354
+ :keepalive => true, :head => { "Host" => "experella.com" })
357
355
  req1.errback {
358
- #this shouldnt happen, but when it does it should at least be because of a timeout
356
+ # this shouldnt happen, but when it does it should at least be because of a timeout
359
357
  time = Time.now - time
360
358
  time.should >= config.timeout
361
359
  time.should < config.timeout + 5
@@ -365,7 +363,7 @@ describe ExperellaProxy do
365
363
  req1.callback {
366
364
  req1.response.should start_with "you sent: "
367
365
  }
368
- #check for inactivity timeout
366
+ # check for inactivity timeout
369
367
  EventMachine.add_periodic_timer(1) do
370
368
  if conn.conn.get_idle_time.nil?
371
369
  time = Time.now - time
@@ -378,22 +376,21 @@ describe ExperellaProxy do
378
376
  end
379
377
  end
380
378
  end
381
- }.should_not raise_error
379
+ end.should_not raise_error
382
380
  end
383
381
  end
384
382
 
385
-
386
383
  it "should handle pipelined requests correctly" do
387
384
  log.info "should handle pipelined requests correctly"
388
385
  EM.epoll
389
386
  EM.run do
390
- lambda {
387
+ lambda do
391
388
  EventMachine.add_timer(0.2) do
392
389
  conn = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}")
393
390
 
394
- pipe1 = conn.get({:connect_timeout => 1, :keepalive => true, :head => {"Host" => "experella.com"}})
395
- pipe2 = conn.get({:path => '/about/', :connect_timeout => 1, :keepalive => true, :head => {"Host" => "experella.com"}})
396
- pipe3 = conn.get({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
391
+ pipe1 = conn.get(:connect_timeout => 1, :keepalive => true, :head => { "Host" => "experella.com" })
392
+ pipe2 = conn.get(:path => '/about/', :connect_timeout => 1, :keepalive => true, :head => { "Host" => "experella.com" })
393
+ pipe3 = conn.get(:connect_timeout => 1, :head => { "Host" => "experella.com" })
397
394
  pipe1.errback {
398
395
  EventMachine.stop
399
396
  raise "http request 1 failed"
@@ -423,7 +420,7 @@ describe ExperellaProxy do
423
420
  EventMachine.stop
424
421
  }
425
422
  end
426
- }.should_not raise_error
423
+ end.should_not raise_error
427
424
  end
428
425
  end
429
426
 
@@ -431,16 +428,16 @@ describe ExperellaProxy do
431
428
  log.info "should accept requests on all set proxy domains"
432
429
  EM.epoll
433
430
  EM.run do
434
- lambda {
431
+ lambda do
435
432
  EventMachine.add_timer(0.2) do
436
433
 
437
434
  multi = EventMachine::MultiRequest.new
438
435
  multi_shuffle = []
439
436
  i = 0
440
- while config.proxy.length > i do
441
- multi_shuffle[i] = Proc.new { |i|
437
+ while config.proxy.length > i
438
+ multi_shuffle[i] = proc { |i|
442
439
  multi.add i, EventMachine::HttpRequest.new("http://#{config.proxy[i][:host]}:#{config.proxy[i][:port]}"
443
- ).get({:connect_timeout => 1, :head => {"Host" => "experella.com"}})
440
+ ).get(:connect_timeout => 1, :head => { "Host" => "experella.com" })
444
441
  }
445
442
  i += 1
446
443
  end
@@ -462,7 +459,7 @@ describe ExperellaProxy do
462
459
  EventMachine.stop
463
460
  end
464
461
  end
465
- }.should_not raise_error
462
+ end.should_not raise_error
466
463
  end
467
464
  end
468
465
 
@@ -470,10 +467,10 @@ describe ExperellaProxy do
470
467
  log.info "should be able to handle post requests"
471
468
  EM.epoll
472
469
  EM.run do
473
- lambda {
470
+ lambda do
474
471
  EventMachine.add_timer(0.2) do
475
472
  http = EventMachine::HttpRequest.new("http://#{config.proxy[0][:host]}:#{config.proxy[0][:port]}"
476
- ).post({:connect_timeout => 1, :head => {"Host" => "experella.com"}, :body => "Message body"})
473
+ ).post(:connect_timeout => 1, :head => { "Host" => "experella.com" }, :body => "Message body")
477
474
  http.errback {
478
475
  EventMachine.stop
479
476
  raise "http post failed"
@@ -484,9 +481,9 @@ describe ExperellaProxy do
484
481
  EventMachine.stop
485
482
  }
486
483
  end
487
- }.should_not raise_error
484
+ end.should_not raise_error
488
485
  end
489
486
  end
490
487
 
491
488
  end
492
- end
489
+ end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe ExperellaProxy::Request do
4
4
 
5
- let(:request) {
5
+ let(:request) do
6
6
  ExperellaProxy::Request.new("conn")
7
- }
7
+ end
8
8
 
9
9
  describe "#new" do
10
10
 
@@ -51,7 +51,7 @@ describe ExperellaProxy::Request do
51
51
 
52
52
  describe "#add_uri" do
53
53
  it "adds a hash to the URI hash" do
54
- request.add_uri({:path => "/hello"})
54
+ request.add_uri(:path => "/hello")
55
55
  request.uri[:path].should eql("/hello")
56
56
  end
57
57
  end
@@ -67,15 +67,15 @@ describe ExperellaProxy::Request do
67
67
  it "overwrites values of existing keys" do
68
68
  request.update_header("Host" => "xyz", :request_url => "abcd")
69
69
  request.update_header("Host" => "abc")
70
- request.header.should eql({:Host => "abc", :request_url => "abcd"})
70
+ request.header.should eql(:Host => "abc", :request_url => "abcd")
71
71
  end
72
72
  end
73
73
 
74
74
  describe "#reconstruct_header" do
75
75
  it "writes a valid http header into send_buffer" do
76
76
  request << "HeaderDummy\r\n\r\n"
77
- request.update_header({:http_method => "GET", :request_url => "/index",
78
- "Host" => "localhost", "Connection" => "keep-alive", :"Via-X" => ["Lukas", "Amy", "George"]})
77
+ request.update_header(:http_method => "GET", :request_url => "/index",
78
+ "Host" => "localhost", "Connection" => "keep-alive", :"Via-X" => %w(Lukas Amy George))
79
79
  request.reconstruct_header
80
80
  data = request.flush
81
81
  data.start_with?("GET /index HTTP/1.1\r\n").should be_true
@@ -85,4 +85,4 @@ describe ExperellaProxy::Request do
85
85
  end
86
86
  end
87
87
 
88
- end
88
+ end