add /kitty route to get a cat picture from CaaS
All checks were successful
Gitea Actions Demo / lint (push) Successful in 19s
Gitea Actions Demo / test (push) Successful in 18s
Gitea Actions Demo / release-image (push) Successful in 2m7s

This commit is contained in:
2025-03-09 20:55:52 -05:00
parent 62f204fa8b
commit 54a3de77e2
3 changed files with 31 additions and 0 deletions

20
app.rb
View File

@ -14,6 +14,8 @@ require "anyflake"
require "jwt"
require "httparty"
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require "config"
@ -495,3 +497,21 @@ get "/bytes/:size" do
generate_bytes(Integer(n))
end
get "/kitty" do
caas_host = ENV.fetch "CAAS_SERVICE_HOST"
caas_port = ENV.fetch "CAAS_SERVICE_PORT"
url = "http://#{caas_host}:#{caas_port}/"
response = HTTParty.head(url)
content_type response.headers["content-type"]
stream do |out|
response = HTTParty.get(url, stream_body: true) do |fragment|
if [301, 302].include? fragment.code
elsif fragment.code == 200
out << fragment
else
raise StandardError, "non-success status code while streaming #{fragment.code}"
end
end
end
end