iodine icon indicating copy to clipboard operation
iodine copied to clipboard

Support X-Sendfile in response to a POST request

Open fgoepel opened this issue 2 years ago • 1 comments

I don't see why this shouldn't be supported, NGINX and Apache do allow it.

fgoepel avatar Jan 10 '22 22:01 fgoepel

Is there a chance of getting this merged at some point? I have a use case for this and would prefer to be able to use the official gem.

fgoepel avatar Jun 01 '22 20:06 fgoepel

It would be nice to get some feedback on this. Without this using Rails send_file in response to a post request just ends up downloading a file containing "Forbidden", which is not ideal from any angle.

fgoepel avatar Apr 28 '23 21:04 fgoepel

OMG, I'm so sorry, I totally missed this PR for some reason...

A quick look would suggest that this would be fine, but it will also effect the static file service (it will answer POST requests... I believe that POST requests should bypass the static file service to be processed as dynamic requests, no?

If we want X-Sendfile to work when responding to POST (but still be ignored by the static file service), that the PR should probably place this conditional in the http_on_request_handler______internal handler just before the call to http_sendfile2:

 /* untested, written into the text box at GitHub, so... */
  if (settings->public_folder &&
      (fiobj_obj2cstr(h->method).len != 4 || !strncasecmp("post", fiobj_obj2cstr(h->method).data, 4))) {
    fio_str_info_s path_str = fiobj_obj2cstr(h->path);
    if (!http_sendfile2(h, settings->public_folder,
                        settings->public_folder_length, path_str.data,
                        path_str.len))
      return;
  }

boazsegev avatar Apr 28 '23 23:04 boazsegev

OMG, I'm so sorry, I totally missed this PR for some reason...

No worries.

I didn't manage to push to this PR's branch for some reason, so I've opened #141 with the requested changes.

fgoepel avatar Apr 29 '23 14:04 fgoepel

I manually tested that it makes X-Sendfile work for POST requests.

fgoepel avatar Apr 29 '23 14:04 fgoepel