From a204ca0458fff21885b21042385c1363ccd69330 Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Sat, 12 Oct 2019 22:02:10 +0200 Subject: [PATCH 1/2] handle options requests Signed-off-by: Alexis Reigel --- template/ruby-http/index.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/template/ruby-http/index.rb b/template/ruby-http/index.rb index c0290dd..6fb3de1 100644 --- a/template/ruby-http/index.rb +++ b/template/ruby-http/index.rb @@ -10,6 +10,12 @@ handler = Handler.new +options '/*' do + res, res_headers, status = handler.run request.body, request.env + + [status || 204, res_headers, res] +end + get '/*' do res, res_headers, status = handler.run request.body, request.env From afae3427d40f396bf663babe6f02422261e2a62d Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Sun, 13 Oct 2019 21:04:49 +0200 Subject: [PATCH 2/2] extract response logic to helper Signed-off-by: Alexis Reigel --- template/ruby-http/index.rb | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/template/ruby-http/index.rb b/template/ruby-http/index.rb index 6fb3de1..c3a0398 100644 --- a/template/ruby-http/index.rb +++ b/template/ruby-http/index.rb @@ -8,34 +8,32 @@ set :port, 5000 # set :bind, '0.0.0.0' -handler = Handler.new +helpers do + def respond_with(default_status) + handler = Handler.new -options '/*' do - res, res_headers, status = handler.run request.body, request.env + res, res_headers, status = handler.run request.body, request.env - [status || 204, res_headers, res] + [status || default_status, res_headers, res] + end end -get '/*' do - res, res_headers, status = handler.run request.body, request.env +options '/*' do + respond_with(204) +end - [status || 200, res_headers, res] +get '/*' do + respond_with(200) end post '/*' do - res, res_headers, status = handler.run request.body, request.env - - [status || 200, res_headers, res] + respond_with(200) end put '/*' do - res, res_headers, status = handler.run request.body, request.env - - [status || 200, res_headers, res] + respond_with(200) end delete '/*' do - res, res_headers, status = handler.run request.body, request.env - - [status || 200, res_headers, res] + respond_with(200) end