未验证 提交 eb3f1e27 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

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

Fix host for ActiveStorage DiskService
上级 661cf579
......@@ -86,8 +86,12 @@ def url(key, expires_in:, filename:, disposition:, content_type:)
purpose: :blob_key }
)
current_uri = URI.parse(current_host)
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,
content_type: content_type,
filename: filename
......
......@@ -7,8 +7,14 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
include ActiveStorage::Service::SharedServiceTests
test "url generation" do
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"))
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/,
@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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册