File tree Expand file tree Collapse file tree 4 files changed +16
-2
lines changed Expand file tree Collapse file tree 4 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
#### Fixes
8
8
9
- * Your contribution here .
9
+ * [ # 2083 ] ( https://github.com/ruby-grape/grape/pull/2083 ) : Set Cache-Control only for streamed responses - [ @ stanhu ] ( https://github.com/stanhu ) .
10
10
11
11
### 1.4.0 (2020/07/10)
12
12
Original file line number Diff line number Diff line change @@ -328,6 +328,8 @@ def sendfile(value = nil)
328
328
# * https://github.com/rack/rack/blob/99293fa13d86cd48021630fcc4bd5acc9de5bdc3/lib/rack/chunked.rb
329
329
# * https://github.com/rack/rack/blob/99293fa13d86cd48021630fcc4bd5acc9de5bdc3/lib/rack/etag.rb
330
330
def stream ( value = nil )
331
+ return if value . nil? && @stream . nil?
332
+
331
333
header 'Content-Length' , nil
332
334
header 'Transfer-Encoding' , nil
333
335
header 'Cache-Control' , 'no-cache' # Skips ETag generation (reading the response up front)
@@ -339,7 +341,7 @@ def stream(value = nil)
339
341
elsif !value . is_a? ( NilClass )
340
342
raise ArgumentError , 'Stream object must respond to :each.'
341
343
else
342
- instance_variable_defined? ( : @stream) ? @stream : nil
344
+ @stream
343
345
end
344
346
end
345
347
Original file line number Diff line number Diff line change @@ -1149,6 +1149,11 @@ class DummyFormatClass
1149
1149
expect ( last_response . headers [ 'Content-Type' ] ) . to eq ( 'text/plain' )
1150
1150
end
1151
1151
1152
+ it 'does not set Cache-Control' do
1153
+ get '/foo'
1154
+ expect ( last_response . headers [ 'Cache-Control' ] ) . to eq ( nil )
1155
+ end
1156
+
1152
1157
it 'sets content type for xml' do
1153
1158
get '/foo.xml'
1154
1159
expect ( last_response . headers [ 'Content-Type' ] ) . to eq ( 'application/xml' )
Original file line number Diff line number Diff line change @@ -351,6 +351,12 @@ def initialize
351
351
expect ( subject . header [ 'Cache-Control' ] ) . to eq 'no-cache'
352
352
end
353
353
354
+ it 'does not change Cache-Control header' do
355
+ subject . stream
356
+
357
+ expect ( subject . header [ 'Cache-Control' ] ) . to eq 'cache'
358
+ end
359
+
354
360
it 'sets Content-Length header to nil' do
355
361
subject . stream file_path
356
362
@@ -419,6 +425,7 @@ def initialize
419
425
420
426
it 'returns default' do
421
427
expect ( subject . stream ) . to be nil
428
+ expect ( subject . header [ 'Cache-Control' ] ) . to eq nil
422
429
end
423
430
end
424
431
You can’t perform that action at this time.
0 commit comments