From d4c8e8cf96be79a00e02680748cf16f8a7e44a8c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 28 Nov 2011 10:42:39 -0500 Subject: [PATCH] ensure some sort of host for rack::mockrequests that don't provide one --- lib/rack/livereload.rb | 2 +- spec/rack/livereload_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 4fa99ac..89d1a52 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -54,7 +54,7 @@ module Rack body.each do |line| if !headers['X-Rack-LiveReload'] && line[''] - host_to_use = @options[:host] || env['HTTP_HOST'].gsub(%r{:.*}, '') + host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '') if use_vendored? src = LIVERELOAD_JS_PATH.dup + "?host=#{host_to_use}" diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index ed43d36..fb530b1 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -124,6 +124,14 @@ describe Rack::LiveReload do body.should_not include('web_socket') end end + + context 'no host at all' do + let(:env) { {} } + + it 'should use localhost' do + body.should include('localhost') + end + end end context '/__rack/livereload.js' do