Sha256: f81bed1337bdc49c29656f44ad74f07decdbba5b1528b72911315736bcc7088a

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

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

    options = {
      method: 'GET',
      'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect',
      'HTTP_X_ACCEL_MAPPING' => '/accel/mapping/=/replaced/'
    }
    env = Rack::MockRequest.env_for('/', options)
    app.call(env)
  end

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

    it 'contains Sendfile headers' do
      headers = subject[1]
      expect(headers).to include('X-Accel-Redirect')
    end
  end

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

    it 'not contains Sendfile headers' do
      headers = subject[1]
      expect(headers).not_to include('X-Accel-Redirect')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-1.8.0 spec/grape/integration/rack_sendfile_spec.rb
grape-1.7.1 spec/grape/integration/rack_sendfile_spec.rb
grape-1.7.0 spec/grape/integration/rack_sendfile_spec.rb