Skip to content

Commit

Permalink
fixup! un-deprecate stream-like objects
Browse files Browse the repository at this point in the history
  • Loading branch information
urkle committed Jun 9, 2020
1 parent 5fec2a6 commit 8f8609c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3168,7 +3168,9 @@ 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 `sendfile`
You can also set the response to a file with `sendfile`. This works with the
[Rack::Sendfile](https://www.rubydoc.info/gems/rack/Rack/Sendfile) middleware to optimally send
the file through your web server software.
```ruby
class API < Grape::API
Expand All @@ -3178,7 +3180,7 @@ class API < Grape::API
end
```
To stream a file use `stream`
To stream a file in chunks use `stream`
```ruby
class API < Grape::API
Expand All @@ -3188,7 +3190,7 @@ class API < Grape::API
end
```
If you want to stream non-file data you use the stream method and a `Stream` object.
If you want to stream non-file data use the `stream` method and a `Stream` object.
This is an object that responds to `each` and yields for each chunk to send to the client.
Each chunk will be sent as it is yielded instead of waiting for all of the content to be available.
Expand Down
8 changes: 4 additions & 4 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Upgrading Grape
===============

### Upgrading to >= 1.3.4
### Upgrading to >= 1.4.0

#### Reworking stream and file and un-deprecating stream like-objects

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.
This release deprecated `file` in favor of `sendfile` to better document its purpose.

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)
```ruby
class API < Grape::API
get '/' do
Expand All @@ -18,7 +18,7 @@ class API < Grape::API
end
```

Use `stream` to stream files
Use `stream` to stream file content in chunks

```ruby
class API < Grape::API
Expand Down
20 changes: 12 additions & 8 deletions spec/grape/integration/rack_sendfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

describe Rack::Sendfile do
subject do
send_file = file_streamer
contet_object = file_object
app = Class.new(Grape::API) do
use Rack::Sendfile
format :json
get do
file send_file
if contet_object.is_a?(String)
sendfile contet_object
else
stream contet_object
end
end
end

Expand All @@ -22,9 +26,9 @@
app.call(env)
end

context do
let(:file_streamer) do
double(:file_streamer, to_path: '/accel/mapping/some/path')
context 'when calling sendfile' do
let(:file_object) do
'/accel/mapping/some/path'
end

it 'contains Sendfile headers' do
Expand All @@ -33,9 +37,9 @@
end
end

context do
let(:file_streamer) do
double(:file_streamer)
context 'when streaming non file content' do
let(:file_object) do
double(:file_object, each: nil)
end

it 'not contains Sendfile headers' do
Expand Down

0 comments on commit 8f8609c

Please sign in to comment.