@@ -25,9 +25,7 @@ class HelloWorld
25
25
PLAINTEXT_TYPE = 'text/plain'
26
26
DATE = 'Date'
27
27
SERVER = 'Server'
28
- SERVER_STRING = if defined? ( PhusionPassenger )
29
- 'Passenger'
30
- elsif defined? ( Puma )
28
+ SERVER_STRING = if defined? ( Puma )
31
29
'Puma'
32
30
elsif defined? ( Iodine )
33
31
'Iodine'
@@ -64,20 +62,6 @@ def initialize
64
62
@db = PgDb . new ( DEFAULT_DATABASE_URL , max_connections )
65
63
end
66
64
67
- def respond ( content_type , body = '' )
68
- headers = {
69
- CONTENT_TYPE => content_type ,
70
- DATE => Time . now . utc . httpdate ,
71
- SERVER => SERVER_STRING
72
- }
73
- headers [ CONTENT_LENGTH ] = body . bytesize . to_s if defined? ( Unicorn )
74
- [
75
- 200 ,
76
- headers ,
77
- [ body ]
78
- ]
79
- end
80
-
81
65
def fortunes
82
66
fortunes = @db . select_fortunes
83
67
fortunes << { id : 0 , message : 'Additional fortune added at request time.' }
@@ -118,4 +102,39 @@ def call(env)
118
102
respond PLAINTEXT_TYPE , 'Hello, World!'
119
103
end
120
104
end
105
+
106
+ private
107
+
108
+ def respond ( content_type , body )
109
+ [
110
+ 200 ,
111
+ headers ( content_type , body ) ,
112
+ [ body ]
113
+ ]
114
+ end
115
+
116
+ if defined? ( Unicorn )
117
+ def headers ( content_type , body )
118
+ {
119
+ CONTENT_TYPE => content_type ,
120
+ SERVER => SERVER_STRING ,
121
+ CONTENT_LENGTH => body . bytesize . to_s
122
+ }
123
+ end
124
+ elsif defined? ( Falcon ) || defined? ( Puma )
125
+ def headers ( content_type , _ )
126
+ {
127
+ CONTENT_TYPE => content_type ,
128
+ SERVER => SERVER_STRING ,
129
+ DATE => Time . now . utc . httpdate
130
+ }
131
+ end
132
+ else
133
+ def headers ( content_type , _ )
134
+ {
135
+ CONTENT_TYPE => content_type ,
136
+ SERVER => SERVER_STRING
137
+ }
138
+ end
139
+ end
121
140
end
0 commit comments