Skip to content

Commit

Permalink
add optional response status
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Reigel <mail@koffeinfrei.org>
  • Loading branch information
koffeinfrei authored and alexellis committed Oct 13, 2019
1 parent 16d5e9b commit 5d193e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Edit the `homepage/handler.rb` file to return some HTML:
```ruby
class Handler
def run(body, headers)
status_code = 200 # Optional status code, defaults to 200
response_headers = {"content-type": "text/html"}
body = "<html>Hello world from the Ruby template</html>"

return body, response_headers
return body, response_headers, status_code
end
end
```
Expand Down
3 changes: 2 additions & 1 deletion template/ruby-http/function/handler.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Handler
def run(body, headers)
status_code = 200 # Optional status code, defaults to 200
response_headers = {"content-type": "text/plain"}
body = "Hello world from the Ruby template"

return body, response_headers
return body, response_headers, status_code
end
end
16 changes: 8 additions & 8 deletions template/ruby-http/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
handler = Handler.new

get '/*' do
res, res_headers = handler.run request.body, request.env
res, res_headers, status = handler.run request.body, request.env

[200, res_headers, res]
[status || 200, res_headers, res]
end

post '/*' do
res, res_headers = handler.run request.body, request.env
res, res_headers, status = handler.run request.body, request.env

[200, res_headers, res]
[status || 200, res_headers, res]
end

put '/*' do
res, res_headers = handler.run request.body, request.env
res, res_headers, status = handler.run request.body, request.env

[200, res_headers, res]
[status || 200, res_headers, res]
end

delete '/*' do
res, res_headers = handler.run request.body, request.env
res, res_headers, status = handler.run request.body, request.env

[200, res_headers, res]
[status || 200, res_headers, res]
end

0 comments on commit 5d193e6

Please sign in to comment.