lib/faastruby/server/app.rb in faastruby-0.5.25 vs lib/faastruby/server/app.rb in faastruby-0.5.26

- old
+ new

@@ -11,10 +11,11 @@ include FaaStRuby::Logger::Requests set :show_exceptions, true set :logging, true set :root, SERVER_ROOT set :public_folder, FaaStRuby::ProjectConfig.public_dir + set :static, true set :static_cache_control, [:must_revalidate, :proxy_revalidate, :max_age => 0] register Sinatra::MultiRoute before do cache_control :must_revalidate, :proxy_revalidate, :max_age => 0 @@ -31,11 +32,11 @@ # else # body = parse_body(request.body.read, headers['Content-Type'], request.request_method) # rpc_args = [] # end - body = parse_body(request.body.read, request_headers['Content-Type'], request.request_method) + body = parse_body(request, request_headers['Content-Type'], request.request_method) rpc_args = [] request_headers['X-Request-Id'] = request_uuid request_headers['Request-Method'] = request.request_method original_request_id = request_headers['X-Original-Request-Id'] query_params = parse_query(request.query_string) @@ -82,17 +83,26 @@ def is_a_function?(name) File.file?("#{FaaStRuby::ProjectConfig.functions_dir}/#{name}/faastruby.yml") end - def parse_body(body, content_type, method) + def parse_body(request, content_type, method) return nil if method == 'GET' - return {} if body.nil? && method != 'GET' - # return Oj.load(body) if content_type == 'application/json' - return body + return form_content(request.env) if content_type == 'application/x-www-form-urlencoded' + body_content(request.body) end + def form_content(request_env) + return {} if (content = request_env['rack.request.form_hash']).nil? + content.to_json + end + + def body_content(request_body) + return {} if (content = request_body.read).nil? + content + end + def parse_query(query_string) hash = {} query_string.split('&').each do |param| key, value = param.split('=') hash[key] = value @@ -111,6 +121,6 @@ result['Content-Length'] = env['CONTENT_LENGTH'] result['Remote-Addr'] = env['REMOTE_ADDR'] result end end -end \ No newline at end of file +end