Bug in handling POST then sending a file back
Maxim Dounin
mdounin at mdounin.ru
Mon Jan 8 20:49:54 UTC 2024
Hello!
On Sun, Jan 07, 2024 at 09:41:33PM -0500, Saint Michael wrote:
> I am using openresty and nginx.
> I send a file to the server, which is a POST operation. Then the
> server processes the file and needs to send back a different file. I
> try to send a file with ng.exec("/static/file_name") and I get error
> 405 Not Allowed.
> But if I do a 302 redirect, it works.
> I imagine that Nginx feels bad about sending a file in a POST
> operation, but http does not have such a limitation.
> Is there a workaround for this?
As far as I can see from the Lua module docs, ngx.exec() you are
using in your script does an internal redirect. As the result,
nginx ends up with a POST request to a static file, which is not
something nginx can handle: it does not know what to do with data
POSTed to a static file, hence the error.
If you've already processed POSTed data, and want to show some
static message to a client, consider returning a redirect to the
static file to the user, such as 303 (See Other), see
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303 for a
good description.
If you are sure you want to return the file as a response to the
POST request itself (this is generally a bad practice, since it
will break page refresh and browser history navigation), consider
returning the file directly from your script instead of trying to
do an internal redirect.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list