From 96021984e69c98f9a3dfbe90462efd47a6b9481a Mon Sep 17 00:00:00 2001 From: Chris W Date: Mon, 15 Jan 2024 14:35:56 -0700 Subject: [PATCH] Allow following redirects when passing a URL --- .vscode/settings.json | 3 +++ shard.yml | 3 +++ src/controllers/paste_controller.cr | 1 - src/services/utils_service.cr | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5a2744b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "crystal-lang.mainFile": "${workspaceRoot}/src/main.cr" +} \ No newline at end of file diff --git a/shard.yml b/shard.yml index 2ba8d2a..df13285 100644 --- a/shard.yml +++ b/shard.yml @@ -10,6 +10,9 @@ targets: cli: main: src/console.cr +crystalline: + main: src/main.cr + dependencies: athena: github: athena-framework/framework diff --git a/src/controllers/paste_controller.cr b/src/controllers/paste_controller.cr index ad1090b..b63eaa8 100644 --- a/src/controllers/paste_controller.cr +++ b/src/controllers/paste_controller.cr @@ -38,7 +38,6 @@ module Paste69 raise ATH::Exceptions::BadRequest.new("Missing token") end - if fd.has_key?("delete") paste.delete return ATH::Response.new("", status: 200) diff --git a/src/services/utils_service.cr b/src/services/utils_service.cr index 18ef5cb..b8755be 100644 --- a/src/services/utils_service.cr +++ b/src/services/utils_service.cr @@ -88,6 +88,12 @@ module Paste69 headers = HTTP::Headers{ "Accept-Encoding" => "identity" } res = HTTP::Client.get(url, headers: headers) + attempts = 1 + + while (location = res.headers["Location"]?) && attempts <= 3 + res = HTTP::Client.get(location, headers: headers) + attempts += 1 + end if res.status.to_i >= 300 raise ATH::Exceptions::BadRequest.new("URL response was not OK")