diff options
Diffstat (limited to 'config/initializers/grape_patch.rb')
-rw-r--r-- | config/initializers/grape_patch.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/config/initializers/grape_patch.rb b/config/initializers/grape_patch.rb new file mode 100644 index 00000000000..a9ac0840541 --- /dev/null +++ b/config/initializers/grape_patch.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true +# Monkey patch for Grape v1.4.0: https://github.com/ruby-grape/grape/pull/2088 + +require 'grape' + +# rubocop:disable Gitlab/ModuleWithInstanceVariables +module Grape + module DSL + module InsideRoute + def stream(value = nil) + return if value.nil? && @stream.nil? + + header 'Content-Length', nil + header 'Transfer-Encoding', nil + header 'Cache-Control', 'no-cache' # Skips ETag generation (reading the response up front) + + if value.is_a?(String) + file_body = Grape::ServeStream::FileBody.new(value) + @stream = Grape::ServeStream::StreamResponse.new(file_body) + elsif value.respond_to?(:each) + @stream = Grape::ServeStream::StreamResponse.new(value) + elsif !value.is_a?(NilClass) + raise ArgumentError, 'Stream object must respond to :each.' + else + @stream + end + end + end + end +end +# rubocop:enable Gitlab/ModuleWithInstanceVariables |