Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Remove Middleware #69

Open
felixbuenemann opened this issue Jan 10, 2015 · 5 comments
Open

[RFC] Remove Middleware #69

felixbuenemann opened this issue Jan 10, 2015 · 5 comments

Comments

@felixbuenemann
Copy link
Collaborator

I propose to remove the Rack Middleware that alters some headers for the iframe transport.

  • In the past (and currently) the required patches to the jquery-file-upload javscript sources have often been neglected, so it was mostly not active
  • It is not generally needed, if the proper content type is returned from the controller that handles uploads and the jquery file upload wiki already contains instruction on how to do that
  • It modifies the body to add some wrapper html code to inject original response data, which is no longer present in recent versions of rails due to the streaming support wrapping the original rack response
  • Above mentioned wrapper html breaks non-html content handling in the jquery iframe transport (json, xml, script), because the transport expects the iframe body to contain either json, xml or javascript, but not the html/textarea wrapper added by the middleware

It's also hard to adapt the middleware to handle all the different cases of data that might be returned and is supported by the jquery iframe transport, so this is better handled inside the app's controller.

@felixbuenemann
Copy link
Collaborator Author

@tors @opti What do you think?

@opti
Copy link
Collaborator

opti commented Jan 16, 2015

@felixbuenemann I have no objections on that. However, I have never faced to the necessity of using this middleware for all the time I have been using this gem.

@tors
Copy link
Owner

tors commented Jan 17, 2015

@felixbuenemann Reasonable points. Let's go ahead and remove the middleware.

@jhubert
Copy link

jhubert commented Jun 30, 2015

@felixbuenemann I've been struggling with iframe transport and rails and this middleware helped. Are you able to give some examples as to how you handle this in the controller without the middleware?

@felixbuenemann
Copy link
Collaborator Author

@jhubert I haven't looked at this for a long time. It seems that at the very least the client would have to add a header like 'X-Requested-With: IFrame' so the controller could detect iframe requests and then alter the Content-Type to text/html so eg IE wouldn't show a download prompt. It can then return the response wrapped in a textarea which has data-type, data-status and data-statusText attributes with the relevant data. This is documented in the jquery-iframe-transport.js docs.

I do remember discussing this issue upstream, where I did a PR to include the 'X-Requested-With: IFrame' header in the ajax request, but it was rejected because supposedly there's another way to detect this. If your controller only accepts requests from jquery file uploader, then for non-iframe request request.xhr? will be truthy and for iframe requests if will be falsy. This technique does not help you if you get normal form uploads without js to the same controller action, because they will look the same as the iframe upload.

You can then do something like this:

respond_to do |format|
  format.html do
    if request.xhr?
      # render normal response
    else
      # render response wrapped in textarea for iframe transport
    end
  end
end

Repository owner deleted a comment from skodumur Feb 20, 2024
Repository owner deleted a comment from leojin Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants