Danbooru::Http: redirect POST to GET on 302.
When a POST request returns a 302 redirect, follow the redirect with a GET request instead of with a POST request. HTTP standards leave it unspecified whether a POST request that returns a 302 redirect should be followed with a GET or with a POST. A GET is what most browsers use, which means it's what most servers expect. Fixes the /tagme Discord command not working because when we uploaded the image to DeepDanbooru, the POST request returned a 302 redirect, which the server expected us to follow with a GET, not with a POST. Ref: * https://stackoverflow.com/questions/17605915/what-is-the-correct-behavior-expected-of-an-http-post-302-redirect-to-get
This commit is contained in:
@@ -31,7 +31,7 @@ module Danbooru
|
||||
uri = HTTP::URI.parse(location)
|
||||
|
||||
verb = request.verb
|
||||
verb = :get if response.status == 303 && !request.verb.in?([:get, :head])
|
||||
verb = :get if response.status.in?([302, 303]) && !request.verb.in?([:get, :head])
|
||||
|
||||
request.redirect(uri, verb)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user