Skip to content

Commit

Permalink
Update to Grape v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stanhu authored and Igor Drozdov committed Jul 15, 2020
1 parent e948fb1 commit 94e343e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ gem 'gitlab_omniauth-ldap', '~> 2.1.1', require: 'omniauth-ldap'
gem 'net-ldap'

# API
gem 'grape', '~> 1.3.3'
# Locked at Grape v1.4.0 until https://github.com/ruby-grape/grape/pull/2088 is merged
# Remove config/initializers/grape_patch.rb
gem 'grape', '= 1.4.0'
gem 'grape-entity', '~> 0.7.1'
gem 'rack-cors', '~> 1.0.6', require: 'rack/cors'

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ GEM
signet (~> 0.14)
gpgme (2.0.20)
mini_portile2 (~> 2.3)
grape (1.3.3)
grape (1.4.0)
activesupport
builder
dry-types (>= 1.1)
Expand Down Expand Up @@ -1268,7 +1268,7 @@ DEPENDENCIES
google-api-client (~> 0.33)
google-protobuf (~> 3.8.0)
gpgme (~> 2.0.19)
grape (~> 1.3.3)
grape (= 1.4.0)
grape-entity (~> 0.7.1)
grape-path-helpers (~> 1.3)
grape_logging (~> 1.7)
Expand Down
5 changes: 5 additions & 0 deletions changelogs/unreleased/sh-update-grape-1-4-0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Update to Grape v1.4.0
merge_request: 36628
author:
type: fixed
31 changes: 31 additions & 0 deletions config/initializers/grape_patch.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/api/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def present_disk_file!(path, filename, content_type = 'application/octet-stream'
header['X-Sendfile'] = path
body
else
file path
sendfile path
end
end

Expand Down

0 comments on commit 94e343e

Please sign in to comment.