envoy-proxy 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef2118712910e35819c817d33c0e2d6b7f9d502b
4
- data.tar.gz: 88ae6105ccd8b45c4c21b2ca5f3550eaec77de9f
3
+ metadata.gz: 6d9b0f4972a7646dbf5c14d62a4dd6b22b38b916
4
+ data.tar.gz: d8d329bb6236ff90676eb4b3bd87049e76754d6b
5
5
  SHA512:
6
- metadata.gz: f37e81842ec29acd108aa83d71f9d0a8b802d8b5e47cc914a2b134110b525c133aeecdad66ad530a13a7210b32f8ec9fed8f28e6f0b52f9ee751d04369d19e70
7
- data.tar.gz: 57e5090d881c0d67b267114332cb8a9665f1c22a2e8e2f98dbf06610f475b9ae8313169367caeb826b5723991e0ff7ef5f9fec6d21a8639210a1769eb8667ce7
6
+ metadata.gz: ba994c1c737f4a6ec79b790bd899615e75a26da0322fe0189cb3ffeeaa46d0598617bfcab2f91df1cdd840ccd7fed06c17f89dddf63d9935260875def10a52ed
7
+ data.tar.gz: 906a1e74a93456b3c971b0c15bf398ad79b1213a01a8dd5066cd1d0f0adacdae94d6c4cd18ac52d7010faaf509200d4313d808e00906a51ee32c649263f366b0
@@ -43,7 +43,8 @@ module Envoy
43
43
  end
44
44
 
45
45
  def receive_message message
46
- STDERR.puts message
46
+ t = Time.now.strftime("%F %T")
47
+ STDERR.puts t + " " + message.split("\n").join("\n#{t.gsub(/./, ' ')} ")
47
48
  end
48
49
 
49
50
  def receive_halt
@@ -51,10 +52,10 @@ module Envoy
51
52
  end
52
53
 
53
54
  def unbind
54
- if @options[:reconnect]
55
- STDERR.puts "No connection. Reconnecting in #{@options[:reconnect]}s."
56
- EM.add_timer @options[:reconnect] do
57
- @options[:reconnect] *= 2
55
+ if r = @options[:reconnect]
56
+ STDERR.puts "Lost connection. Reconnecting in #{r[0]}s."
57
+ EM.add_timer r[0] do
58
+ @options[:reconnect] = [r[1], r[0] + r[1]]
58
59
  Trunk.start @options
59
60
  end
60
61
  else
@@ -69,7 +70,7 @@ module Envoy
69
70
 
70
71
  def ssl_handshake_completed
71
72
  options[:did_connect] = true
72
- options[:reconnect] = 1 if options[:hosts]
73
+ options[:reconnect] = [0, 1] if options[:hosts]
73
74
  o = options.dup
74
75
  o.delete(:local_host)
75
76
  send_object :options, o
@@ -18,6 +18,10 @@ module Envoy
18
18
  @trunk.send_object :stream, id, data
19
19
  end
20
20
 
21
+ def message data
22
+ @trunk.send_object :message, data
23
+ end
24
+
21
25
  def id
22
26
  @id ||= SecureRandom.hex(4)
23
27
  end
@@ -26,4 +30,3 @@ module Envoy
26
30
 
27
31
  end
28
32
  end
29
-
@@ -46,11 +46,12 @@ module Envoy
46
46
  end
47
47
  end
48
48
  hosts << SecureRandom.random_number(36 ** 4).to_s(36) if hosts.empty?
49
- send_object :message, "Local server on port #{options[:local_port]} is now publicly available via:"
49
+ m = ["Local server on port #{options[:local_port]} is now publicly available via:"]
50
50
  @hosts = hosts.each do |host|
51
51
  Trunk.trunks[host] << self
52
- send_object :message, "http://#{host}.#{$zone}/"
52
+ m << "http://#{host}.#{$zone}/"
53
53
  end
54
+ send_object :message, m.join("\n")
54
55
  end
55
56
 
56
57
  def unbind
@@ -8,6 +8,7 @@ module Envoy
8
8
 
9
9
  def post_init
10
10
  @header = ""
11
+ @connection = "close"
11
12
  end
12
13
 
13
14
  def unbind
@@ -15,17 +16,26 @@ module Envoy
15
16
  end
16
17
 
17
18
  def receive_line line
18
- @header << line + "\r\n"
19
- if line =~ /^Host: ([^:]*)/
20
- host = $1
21
- raise "Request is not in #{$zone}" unless host.end_with?($zone)
22
- host = host[0...-$zone.length]
23
- host = host.split(".").last
24
- trunk = Trunk.trunks[host].sample || raise("No trunk for #{host}.#{$zone}")
19
+ @first_line ||= line
20
+ if line == ""
21
+ trunk = Trunk.trunks[@host].sample || raise("No trunk for #{@host}.#{$zone}")
22
+ @header << "Connection: #{@connection}\r\n"
25
23
  @channel = Channel.new(trunk, self, @header)
24
+ @channel.message "%s %s" % [Socket.unpack_sockaddr_in(get_peername)[1], @first_line]
26
25
  set_text_mode
26
+ elsif line =~ /^connection:\s*upgrade$/i
27
+ @connection = "upgrade"
28
+ elsif line =~ /^keep-alive:/i
29
+ elsif line =~ /^host:\s*([^:]*)/i
30
+ @host = $1
31
+ @host = @host[0...-$zone.length]
32
+ @host = @host.split(".").last
33
+ raise "Request is not in #{$zone}" unless @host.end_with?($zone)
34
+ @header << line + "\r\n"
27
35
  elsif @header.size > 4096
28
36
  raise "Header's too long for my liking"
37
+ else
38
+ @header << line + "\r\n"
29
39
  end
30
40
  rescue RuntimeError => e
31
41
  send_data "HTTP/1.0 500 Internal Server Error\r\n"
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Envoy
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.9'
4
4
  end
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envoy-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Baum