Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/app_profiler/viewer/speedscope_remote_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ def view(response: nil, autoredirect: nil, async: false)
id = Middleware.id(@profile.file)

if response && response[0].to_i < 500
response[1]["Location"] = "/app_profiler/#{id}"
response[0] = 303
if autoredirect
response[0] = 303
response[1]["Location"] = "/app_profiler/#{id}"
elsif AppProfiler.profile_header
response[1][AppProfiler.profile_header] = "/app_profiler/#{id}"
end
else
AppProfiler.logger.info("[Profiler] Profile available at /app_profiler/#{id}\n")
end
Expand Down
17 changes: 15 additions & 2 deletions test/app_profiler/viewer/speedscope_remote_viewer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ class SpeedscopeRemoteViewerTest < TestCase
viewer.view
end

test "#view with response redirects to URL" do
test "#view with response sets the profiler header" do
response = [200, {}, ["OK"]]
profile = BaseProfile.from_stackprof(stackprof_profile)

view = SpeedscopeRemoteViewer.new(profile)
id = SpeedscopeRemoteViewer::Middleware.id(profile.file)

view.view(response: response)

assert_equal(200, response[0])
assert_equal("/app_profiler/#{id}", response[1][AppProfiler.profile_header])
end

test "#view with response redirects to URL when autoredirect is set" do
response = [200, {}, ["OK"]]
profile = BaseProfile.from_stackprof(stackprof_profile)

viewer = SpeedscopeRemoteViewer.new(profile)
id = SpeedscopeRemoteViewer::Middleware.id(profile.file)

viewer.view(response: response)
viewer.view(response: response, autoredirect: true)

assert_equal(303, response[0])
assert_equal("/app_profiler/#{id}", response[1]["Location"])
Expand Down