-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
un-deprecate stream-like objects #1520
Conversation
b8bfd9a
to
c55c862
Compare
So the new code is handling in Needs an UPGRADING/README too. Thanks. |
This looks very promising! @urkle any chance you can adapt this to the current |
@milgner it maybe a week or so before I get back around to this. It's been on my TODO list to rebase, add tests and re-submit this |
@urkle Any news in this PR? |
@linchus this needs to be rebased and tests added (as requested). Right now it has been a matter of finding the time to work on it. |
c55c862
to
88372d3
Compare
Can we help in some way this PR to be merged? The deprecation warning is really noisy when used in regression tests and clutters the output. Since we're using a non-deprecated object, it would be really useful to remove the warning. |
Reopen the PR, fix per comments above, make it green? |
Right now I'm finishing a project in the next week or so upgrading our apps to using Grape 1.3.x. Once that is done I'll be able to revisit this against grape master (as we are still using this functionality) And this means I'm actually logging a task in our system for me to work on this :) |
@urkle thanks for your effort! |
9e0329e
to
fdf5398
Compare
This looks ready code-wise, thanks for following up! We need to document the new behavior in README? Anything to add to UPGRADING? |
I just rebased it right now. Going through my changes and refreshing my memory and going to be adding more tests and updating README still. I'll let you know when it's all ready. @dblock also did you have any thoughts on my first question in the PR? Why the "stream' method sets headers but not the 'file' method? |
9b12fe6
to
c7da23b
Compare
@dblock ok.. I pushed up new tests and updates to UPGRADING and README. Let me know what else you want me to adjust/tweak. |
I am guessing because for a file you want to let Rack do its thing for content-length and transfer-encoding and generate an e-tag, but for a stream none of these make sense?
I think what you did was right. A file is a file, a stream is a stream. Until someone points out something broken I say leave it. But I would also agree to not deprecate it. Possibly simpler?
I would ensure tests for those headers, if we made a mistake at least we will have tests to say that it was thought through behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README.md
Outdated
@@ -3168,7 +3168,7 @@ end | |||
|
|||
Use `body false` to return `204 No Content` without any data or content-type. | |||
|
|||
You can also set the response to a file with `file`. | |||
You can also set the response to a file with `file` and it will be streamed using Rack::Chunked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote Rack::Chunked
README.md
Outdated
@@ -3178,12 +3178,22 @@ class API < Grape::API | |||
end | |||
``` | |||
|
|||
If you want a file to be streamed using Rack::Chunked, use `stream`. | |||
If you want to stream non-file data you use the stream method and a Stream object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote classes
README.md
Outdated
@@ -3178,12 +3178,22 @@ class API < Grape::API | |||
end | |||
``` | |||
|
|||
If you want a file to be streamed using Rack::Chunked, use `stream`. | |||
If you want to stream non-file data you use the stream method and a Stream object. | |||
This is simply an object that responds to each and yields for each chunk to send to the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "simply", weasel word ;)
Quote each
UPGRADING.md
Outdated
|
||
Previously in 0.16 stream-like objects were deprecated. This release restores their functionality for use-cases other than file streaming. | ||
|
||
For streaming files, simply use file always. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove simply, quote file
UPGRADING.md
Outdated
end | ||
``` | ||
|
||
If you want to stream other kinds of content from a streamer object you may. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or shorter ...
Use stream
to stream other kinds of content. In the following example a streamer class ...
UPGRADING.md
Outdated
class MyObject | ||
def each | ||
yield '[' | ||
# maybe do some paginated DB fetches and return each page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove maybe, another weasel word
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file is purely for specifying a file (and utilizing sendfile when it can)
from the user's point of view, it still sounds ambiguous. at least it should be documented "when it can".
though I would use file
only for utilizing sendfile
(or even rename it to sendfile
) and use stream
to produce a chunked response(this could be a file too): those different delivery mechanisms require different changes to the stack, so I would use different interfaces for them to force a user to make an explicit choice.
moreover sendfile
is not about streaming, it's about an optimization of static file delivering using web server facilities.
@dm1try @dblock
|
I think what is in this PR is good (enough) as it does what it advertises. Before we go into further renaming - @dm1try what do you think about merging this on 🍏 as here and then we can try the suggested change? |
@dblock I pushed a fixup that does that rework.. but I can extract to a separate PR if you wish.. Up to you.. just let me know. |
@dblock I think the rework is definitely cleaner and more obvious. |
I’m fine with it) EDITED: oops, I was late with my comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm cool with this update, it's definitely better.
Let's bump version to 1.4 as part of this PR?
Fix the build.
UPGRADING.md
Outdated
|
||
Previously in 0.16 stream-like objects were deprecated. This release restores their functionality for use-cases other than file streaming. | ||
|
||
This release also renamed `file` to `sendfile` to better document it's purpose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's -> its
We're deprecating file
, so I would say "this release deprecated file
in favor of sendfile
"
UPGRADING.md
Outdated
|
||
This release also renamed `file` to `sendfile` to better document it's purpose. | ||
|
||
To deliver a file via `sendfile` if available do this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"if available" doesn't make sense to me, I would just remove
to deliver "in chunks" or something similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock look at how I re-worded it.. as it is not really "in chunks" as if the web server you are running through supports sendfile then it hands it off to that functionality.
UPGRADING.md
Outdated
end | ||
``` | ||
|
||
Use `stream` to stream files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"stream file conntent"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the typo below, squash and I'll merge. Thanks for hanging in here!
@@ -4,12 +4,16 @@ | |||
|
|||
describe Rack::Sendfile do | |||
subject do | |||
send_file = file_streamer | |||
contet_object = file_object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content_object, typo, missing n
UPGRADING.md
Outdated
|
||
To deliver a file via `sendfile` if available do this. | ||
To deliver a file via the Sendfile support in your web server and have the Rack::Sendfile middleware enabled. See [`Rack::Sendfile`](https://www.rubydoc.info/gems/rack/Rack/Sendfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a period in the end.
UPGRADING.md
Outdated
@@ -18,7 +18,7 @@ class API < Grape::API | |||
end | |||
``` | |||
|
|||
Use `stream` to stream files | |||
Use `stream` to stream file content in chunks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a period.
Since we're bumping to 1.4, change version.rb and the version in CHANGELOG too please. |
- deprecate file and replace with sendfile - update stream to not deprecate stream-like objects
8f8609c
to
3db3b0a
Compare
Merged, thank you! |
I suggest sending an email to the Grape mailing list describing the change (mostly copy from upgrading) and asking people to comment/test/etc. early. |
ServeFile was renamed to ServeStream in ruby-grape#1520. Calling Grape.eager_load! would fail with: ``` uninitialized constant Grape::ServeFile (NameError) ```
ServeFile was renamed to ServeStream in ruby-grape#1520. Calling Grape.eager_load! would fail with: ``` uninitialized constant Grape::ServeFile (NameError) ```
ServeFile was renamed to ServeStream in ruby-grape#1520. Calling Grape.eager_load! would fail with: ``` uninitialized constant Grape::ServeFile (NameError) ```
ServeFile was renamed to ServeStream in #1520. Calling Grape.eager_load! would fail with: ``` uninitialized constant Grape::ServeFile (NameError) ```
The pull request ruby-grape#1520 introduced a regression that always caused the `Cache-Control` HTTP header to be set to `no-cache`, even if the response wasn't a stream. To fix this, we only set HTTP headers if there is an actual stream. Closes ruby-grape#2087
The pull request ruby-grape#1520 introduced a regression that always caused the `Cache-Control` HTTP header to be set to `no-cache`, even if the response wasn't a stream. To fix this, we only set HTTP headers if there is an actual stream. Closes ruby-grape#2087
The pull request ruby-grape#1520 introduced a regression that always caused the `Cache-Control` HTTP header to be set to `no-cache`, even if the response wasn't a stream. To fix this, we only set HTTP headers if there is an actual stream. Closes ruby-grape#2087
The pull request ruby-grape#1520 introduced a regression that always caused the `Cache-Control` HTTP header to be set to `no-cache`, even if the response wasn't a stream. To fix this, we only set HTTP headers if there is an actual stream. Closes ruby-grape#2087
The pull request ruby-grape#1520 introduced a regression that always caused the `Cache-Control` HTTP header to be set to `no-cache`, even if the response wasn't a stream. To fix this, we only set HTTP headers if there is an actual stream. Closes ruby-grape#2087
This PR is in reference to issue #1392
Pending Questions