1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36642 from wagenet/fix-disk-service-host

Fix host for ActiveStorage DiskService
This commit is contained in:
Rafael França 2019-07-23 10:37:47 -04:00 committed by GitHub
commit fc175375e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -84,8 +84,12 @@ module ActiveStorage
purpose: :blob_key } purpose: :blob_key }
) )
current_uri = URI.parse(current_host)
generated_url = url_helpers.rails_disk_service_url(verified_key_with_expiration, generated_url = url_helpers.rails_disk_service_url(verified_key_with_expiration,
host: current_host, protocol: current_uri.scheme,
host: current_uri.host,
port: current_uri.port,
disposition: content_disposition, disposition: content_disposition,
content_type: content_type, content_type: content_type,
filename: filename filename: filename

View file

@ -8,8 +8,14 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
include ActiveStorage::Service::SharedServiceTests include ActiveStorage::Service::SharedServiceTests
test "URL generation" do test "URL generation" do
original_url_options = Rails.application.routes.default_url_options.dup
Rails.application.routes.default_url_options.merge!(protocol: "http", host: "test.example.com", port: 3001)
begin
assert_match(/^https:\/\/example.com\/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/, assert_match(/^https:\/\/example.com\/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/,
@service.url(@key, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png")) @service.url(@key, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png"))
ensure
Rails.application.routes.default_url_options = original_url_options
end
end end
test "headers_for_direct_upload generation" do test "headers_for_direct_upload generation" do