Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

generate a name from the server details

  • Loading branch information...
commit 94a2d399eb81d59f9d66c5d16121611c4d1ae0cd 1 parent 7fd2f6b
@Gibheer Gibheer authored
View
7 lib/zero/request/server.rb
@@ -36,6 +36,13 @@ def initialize(environment)
# get the server software
# @return [String] the server software name
attr_reader :software
+
+ # returns the full name of the server
+ # @return [String] the full address to the server
+ def name
+ return @name if @name
+ @name = protocol + '://' + hostname + ':' + port.to_s
+ end
end
end
end
View
20 spec/unit/zero/request/server/name_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Zero::Request::Server, '#name' do
+ subject { Zero::Request::Server.new(env) }
+ let(:hostname) { 'FooName' }
+ let(:port) { '80' }
+ let(:protocol) { 'http' }
+ let(:result) { 'http://FooName:80' }
+
+ let(:env) { EnvGenerator.get('/foo', {
+ 'SERVER_NAME' => hostname,
+ 'SERVER_PROTOCOL' => protocol,
+ 'SERVER_PORT' => port
+ }) }
+
+ it "generates a name" do
+ expect(subject.name).to match(result)
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.