From 27684e2ef3ef68a24346fe36962791f8a7f2072e Mon Sep 17 00:00:00 2001 From: Eliott Appleford Date: Tue, 5 May 2015 23:56:08 +0100 Subject: [PATCH] Encode hostnames to fix #1510 --- middleman-core/lib/middleman-core/preview_server.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index ad52ce7b..ce6678b7 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -117,6 +117,7 @@ module Middleman config[:ssl_private_key] = opts[:ssl_private_key] if opts[:ssl_private_key] end + @host = Socket.gethostname.tr(' ', '+') @port = @app.config[:port] @https = @app.config[:https] @@ -193,10 +194,7 @@ module Middleman http_opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new File.read ssl_private_key else # use a generated self-signed cert - http_opts[:SSLCertName] = [ - %w(CN localhost), - %w(CN #{Socket.gethostname}) - ].uniq + http_opts[:SSLCertName] = [%w(CN localhost), %W(CN #{host})].uniq end end @@ -264,7 +262,7 @@ module Middleman # Returns the URI the preview server will run on # @return [URI] - def uri(host = Socket.gethostname) + def uri(host=@host) scheme = https? ? 'https' : 'http' URI("#{scheme}://#{host}:#{@port}/") end