debian-mirror-gitlab/app/helpers/workhorse_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
# Helpers to send Git blobs, diffs, patches or archives through Workhorse.
# Workhorse will also serve files when using `send_file`.
module WorkhorseHelper
# Send a Git blob through Workhorse
2018-11-18 11:00:15 +05:30
def send_git_blob(repository, blob, inline: true)
headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))
2019-02-15 15:39:39 +05:30
2021-04-29 21:17:54 +05:30
headers['Content-Disposition'] = content_disposition_for_blob(blob, inline)
2019-02-15 15:39:39 +05:30
# If enabled, this will override the values set above
workhorse_set_content_type!
2018-11-08 19:23:39 +05:30
render plain: ""
end
# Send a Git diff through Workhorse
def send_git_diff(repository, diff_refs)
headers.store(*Gitlab::Workhorse.send_git_diff(repository, diff_refs))
headers['Content-Disposition'] = 'inline'
head :ok
end
2016-08-24 12:49:21 +05:30
# Send a Git patch through Workhorse
def send_git_patch(repository, diff_refs)
headers.store(*Gitlab::Workhorse.send_git_patch(repository, diff_refs))
headers['Content-Disposition'] = 'inline'
head :ok
end
# Archive a Git repository and send it through Workhorse
2018-05-09 12:01:36 +05:30
def send_git_archive(repository, **kwargs)
headers.store(*Gitlab::Workhorse.send_git_archive(repository, **kwargs))
head :ok
end
2016-08-24 12:49:21 +05:30
2022-06-21 17:19:12 +05:30
# Send an entry from artifacts through Workhorse and set safe content type
2020-05-24 23:13:21 +05:30
def send_artifacts_entry(file, entry)
headers.store(*Gitlab::Workhorse.send_artifacts_entry(file, entry))
2022-07-16 23:28:13 +05:30
headers.store(*Gitlab::Workhorse.detect_content_type)
2016-08-24 12:49:21 +05:30
head :ok
end
2016-09-29 09:46:39 +05:30
2021-12-11 22:18:48 +05:30
def send_dependency(dependency_headers, url, filename)
headers.store(*Gitlab::Workhorse.send_dependency(dependency_headers, url))
2021-11-18 22:05:49 +05:30
headers['Content-Disposition'] =
ActionDispatch::Http::ContentDisposition.format(disposition: 'attachment', filename: filename)
headers['Content-Type'] = 'application/gzip'
head :ok
end
2016-09-29 09:46:39 +05:30
def set_workhorse_internal_api_content_type
headers['Content-Type'] = Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE
end
2019-02-15 15:39:39 +05:30
def workhorse_set_content_type!
headers[Gitlab::Workhorse::DETECT_HEADER] = "true"
end
2021-04-17 20:07:23 +05:30
2021-04-29 21:17:54 +05:30
def content_disposition_for_blob(blob, inline)
return 'inline' if inline
ActionDispatch::Http::ContentDisposition.format(disposition: 'attachment', filename: blob.name)
2021-04-17 20:07:23 +05:30
end
end