From dbef92d70e3c1aabea5bd1bcf5f117f68025ac5b Mon Sep 17 00:00:00 2001 From: Amitava Date: Thu, 26 Jun 2014 19:59:27 +0530 Subject: [PATCH] Add support for xip.io --- lib/invoker/power/balancer.rb | 3 ++- spec/invoker/power/balancer_spec.rb | 42 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/invoker/power/balancer.rb b/lib/invoker/power/balancer.rb index 44e9771..91f76d1 100644 --- a/lib/invoker/power/balancer.rb +++ b/lib/invoker/power/balancer.rb @@ -23,6 +23,7 @@ def post_init class Balancer attr_accessor :connection, :http_parser, :session, :protocol DEV_MATCH_REGEX = /([\w-]+)\.dev(\:\d+)?$/ + XIP_IO_MATCH_REGEX = /([\w-]+)\.\d+\.\d+\.\d+\.\d+\.xip\.io(\:\d+)?$/ def self.run(options = {}) start_http_proxy(InvokerHttpProxy, 'http', options) @@ -101,7 +102,7 @@ def frontend_disconnect(backend, name) end def extract_host_from_domain(host) - host.match(DEV_MATCH_REGEX) + host.match(DEV_MATCH_REGEX) || host.match(XIP_IO_MATCH_REGEX) end private diff --git a/spec/invoker/power/balancer_spec.rb b/spec/invoker/power/balancer_spec.rb index 09b2341..b4a41b8 100644 --- a/spec/invoker/power/balancer_spec.rb +++ b/spec/invoker/power/balancer_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' describe Invoker::Power::Balancer do - context "matching domain part of incoming request" do - before do - @balancer = Invoker::Power::Balancer.new(mock("connection"), "http") - end + before do + @balancer = Invoker::Power::Balancer.new(mock("connection"), "http") + end + context "matching domain part of incoming request" do it "should do foo.dev match" do match = @balancer.extract_host_from_domain("foo.dev") expect(match).to_not be_nil @@ -38,4 +38,38 @@ expect(matching_string).to eq("hello-world") end end + + context "matching domain part of incoming request using xip.io" do + it "should do foo.10.0.0.1.xip.io match" do + match = @balancer.extract_host_from_domain("foo.10.0.0.1.xip.io") + expect(match).to_not be_nil + + matching_string = match[1] + expect(matching_string).to eq("foo") + end + + it "should match foo.10.0.0.1.xip.io:1080" do + match = @balancer.extract_host_from_domain("foo.10.0.0.1.xip.io:1080") + expect(match).to_not be_nil + + matching_string = match[1] + expect(matching_string).to eq("foo") + end + + it "should match emacs.bar.10.0.0.1.xip.io" do + match = @balancer.extract_host_from_domain("emacs.bar.10.0.0.1.xip.io") + expect(match).to_not be_nil + + matching_string = match[1] + expect(matching_string).to eq("bar") + end + + it "should match hello-world.10.0.0.1.xip.io" do + match = @balancer.extract_host_from_domain("hello-world.10.0.0.1.xip.io") + expect(match).to_not be_nil + + matching_string = match[1] + expect(matching_string).to eq("hello-world") + end + end end