class FunctionsFramework::Server::AppBase
@private
Constants
- EXCLUDED_PATHS
Public Class Methods
new(config)
click to toggle source
# File lib/functions_framework/server.rb, line 333 def initialize config @config = config end
Public Instance Methods
cloud_events_error_response(error)
click to toggle source
# File lib/functions_framework/server.rb, line 380 def cloud_events_error_response error @config.logger.warn error string_response "#{error.class}: #{error.message}", 400 end
error_response(message)
click to toggle source
# File lib/functions_framework/server.rb, line 385 def error_response message @config.logger.error message message = "Unexpected internal error" unless @config.show_error_details? string_response message, 500 end
excluded_path?(env)
click to toggle source
# File lib/functions_framework/server.rb, line 337 def excluded_path? env path = env[::Rack::SCRIPT_NAME].to_s + env[::Rack::PATH_INFO].to_s EXCLUDED_PATHS.include? path end
interpret_response(response)
click to toggle source
# File lib/functions_framework/server.rb, line 342 def interpret_response response case response when ::Array response when ::Rack::Response response.finish when ::String string_response response, 200 when ::Hash string_response ::JSON.dump(response), 200, content_type: "application/json" when ::CloudEvents::CloudEventsError cloud_events_error_response response when ::StandardError error_response "#{response.class}: #{response.message}\n#{response.backtrace}\n" else error_response "Unexpected response type: #{response.class}" end end
notfound_response()
click to toggle source
# File lib/functions_framework/server.rb, line 361 def notfound_response string_response "Not found", 404 end
string_response(string, status, content_type: nil)
click to toggle source
# File lib/functions_framework/server.rb, line 365 def string_response string, status, content_type: nil string.force_encoding ::Encoding::ASCII_8BIT unless string.valid_encoding? if string.encoding == ::Encoding::ASCII_8BIT content_type ||= "application/octet-stream" else content_type ||= "text/plain" content_type = "#{content_type}; charset=#{string.encoding.name.downcase}" end headers = { "Content-Type" => content_type, "Content-Length" => string.bytesize } [status, headers, [string]] end