lib/nephos-server/server/responder.rb in nephos-server-0.1.11 vs lib/nephos-server/server/responder.rb in nephos-server-0.1.12
- old
+ new
@@ -9,11 +9,11 @@
{'Content-type' => "#{kind}/#{type}" + CT_CHARSET_PREFIX + charset}
end
# @param params [Hash] containing :type => "kind/type", example: "text/html"
def self.ct_specific(params)
- kind, type = params[:type].match(/^(\w+)\/(\w+)$/)[1..2]
+ kind, type = params[:type].to_s.match(/^(\w+)\/(\w+)$/) && Regexp.last_match[1..2]
if kind.nil? or type.nil?
raise InvalidContentType, "params[:type] must match with \"kind/type\""
end
content_type(kind, type)
end
@@ -25,18 +25,17 @@
}
private
# if not :status entry, set to 200
def self.set_default_params_status params
- if (params.keys & [:status]).empty?
- params[:status] ||= 200
- end
+ params[:status] ||= 200
end
def self.set_default_params_type params
- return if not params[:type].nil?
- params[:type] = PRESET_CT[(params.keys & [:plain, :html, :json]).first || :plain]
+ if params[:type].nil?
+ params[:type] = PRESET_CT[(params.keys & [:plain, :html, :json]).first || :plain]
+ end
params[:type] = ct_specific(params)
end
def self.set_default_params_content params
type = (params.keys & [:plain, :html, :json, :content]).first
@@ -63,10 +62,10 @@
params
end
# @param params [Hash, Symbol]
def self.render params
- return [204, plain(), [""]] if params == :empty
+ return [204, ct_specific({type: PRESET_CT[:plain]}), [""]] if params == :empty
params = set_default_params(params)
return [
params[:status],
params[:type],
[params[:content]],