Skip to content

Commit 8f8609c

Browse files
committed
fixup! un-deprecate stream-like objects
1 parent 5fec2a6 commit 8f8609c

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,9 @@ end
31683168
31693169
Use `body false` to return `204 No Content` without any data or content-type.
31703170
3171-
You can also set the response to a file with `sendfile`
3171+
You can also set the response to a file with `sendfile`. This works with the
3172+
[Rack::Sendfile](https://www.rubydoc.info/gems/rack/Rack/Sendfile) middleware to optimally send
3173+
the file through your web server software.
31723174
31733175
```ruby
31743176
class API < Grape::API
@@ -3178,7 +3180,7 @@ class API < Grape::API
31783180
end
31793181
```
31803182
3181-
To stream a file use `stream`
3183+
To stream a file in chunks use `stream`
31823184
31833185
```ruby
31843186
class API < Grape::API
@@ -3188,7 +3190,7 @@ class API < Grape::API
31883190
end
31893191
```
31903192
3191-
If you want to stream non-file data you use the stream method and a `Stream` object.
3193+
If you want to stream non-file data use the `stream` method and a `Stream` object.
31923194
This is an object that responds to `each` and yields for each chunk to send to the client.
31933195
Each chunk will be sent as it is yielded instead of waiting for all of the content to be available.
31943196

UPGRADING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Upgrading Grape
22
===============
33

4-
### Upgrading to >= 1.3.4
4+
### Upgrading to >= 1.4.0
55

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

88
Previously in 0.16 stream-like objects were deprecated. This release restores their functionality for use-cases other than file streaming.
99

10-
This release also renamed `file` to `sendfile` to better document it's purpose.
10+
This release deprecated `file` in favor of `sendfile` to better document its purpose.
1111

12-
To deliver a file via `sendfile` if available do this.
12+
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)
1313
```ruby
1414
class API < Grape::API
1515
get '/' do
@@ -18,7 +18,7 @@ class API < Grape::API
1818
end
1919
```
2020

21-
Use `stream` to stream files
21+
Use `stream` to stream file content in chunks
2222

2323
```ruby
2424
class API < Grape::API

spec/grape/integration/rack_sendfile_spec.rb

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
describe Rack::Sendfile do
66
subject do
7-
send_file = file_streamer
7+
contet_object = file_object
88
app = Class.new(Grape::API) do
99
use Rack::Sendfile
1010
format :json
1111
get do
12-
file send_file
12+
if contet_object.is_a?(String)
13+
sendfile contet_object
14+
else
15+
stream contet_object
16+
end
1317
end
1418
end
1519

@@ -22,9 +26,9 @@
2226
app.call(env)
2327
end
2428

25-
context do
26-
let(:file_streamer) do
27-
double(:file_streamer, to_path: '/accel/mapping/some/path')
29+
context 'when calling sendfile' do
30+
let(:file_object) do
31+
'/accel/mapping/some/path'
2832
end
2933

3034
it 'contains Sendfile headers' do
@@ -33,9 +37,9 @@
3337
end
3438
end
3539

36-
context do
37-
let(:file_streamer) do
38-
double(:file_streamer)
40+
context 'when streaming non file content' do
41+
let(:file_object) do
42+
double(:file_object, each: nil)
3943
end
4044

4145
it 'not contains Sendfile headers' do

0 commit comments

Comments
 (0)