|
@@ -25,9 +25,7 @@ class HelloWorld
|
|
|
PLAINTEXT_TYPE = 'text/plain'
|
|
|
DATE = 'Date'
|
|
|
SERVER = 'Server'
|
|
|
- SERVER_STRING = if defined?(PhusionPassenger)
|
|
|
- 'Passenger'
|
|
|
- elsif defined?(Puma)
|
|
|
+ SERVER_STRING = if defined?(Puma)
|
|
|
'Puma'
|
|
|
elsif defined?(Iodine)
|
|
|
'Iodine'
|
|
@@ -64,20 +62,6 @@ class HelloWorld
|
|
|
@db = PgDb.new(DEFAULT_DATABASE_URL, max_connections)
|
|
|
end
|
|
|
|
|
|
- def respond(content_type, body = '')
|
|
|
- headers = {
|
|
|
- CONTENT_TYPE => content_type,
|
|
|
- DATE => Time.now.utc.httpdate,
|
|
|
- SERVER => SERVER_STRING
|
|
|
- }
|
|
|
- headers[CONTENT_LENGTH] = body.bytesize.to_s if defined?(Unicorn)
|
|
|
- [
|
|
|
- 200,
|
|
|
- headers,
|
|
|
- [body]
|
|
|
- ]
|
|
|
- end
|
|
|
-
|
|
|
def fortunes
|
|
|
fortunes = @db.select_fortunes
|
|
|
fortunes << { id: 0, message: 'Additional fortune added at request time.' }
|
|
@@ -118,4 +102,39 @@ class HelloWorld
|
|
|
respond PLAINTEXT_TYPE, 'Hello, World!'
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+ private
|
|
|
+
|
|
|
+ def respond(content_type, body)
|
|
|
+ [
|
|
|
+ 200,
|
|
|
+ headers(content_type, body),
|
|
|
+ [body]
|
|
|
+ ]
|
|
|
+ end
|
|
|
+
|
|
|
+ if defined?(Unicorn)
|
|
|
+ def headers(content_type, body)
|
|
|
+ {
|
|
|
+ CONTENT_TYPE => content_type,
|
|
|
+ SERVER => SERVER_STRING,
|
|
|
+ CONTENT_LENGTH => body.bytesize.to_s
|
|
|
+ }
|
|
|
+ end
|
|
|
+ elsif defined?(Falcon) || defined?(Puma)
|
|
|
+ def headers(content_type, _)
|
|
|
+ {
|
|
|
+ CONTENT_TYPE => content_type,
|
|
|
+ SERVER => SERVER_STRING,
|
|
|
+ DATE => Time.now.utc.httpdate
|
|
|
+ }
|
|
|
+ end
|
|
|
+ else
|
|
|
+ def headers(content_type, _)
|
|
|
+ {
|
|
|
+ CONTENT_TYPE => content_type,
|
|
|
+ SERVER => SERVER_STRING
|
|
|
+ }
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|