Module: WorkhorseHelper

Included in:
ApplicationController
Defined in:
app/helpers/workhorse_helper.rb

Overview

Helpers to send Git blobs, diffs, patches or archives through Workhorse. Workhorse will also serve files when using ‘send_file`.

Instance Method Summary collapse

Instance Method Details

#content_disposition_for_blob(blob, inline) ⇒ Object



63
64
65
66
67
# File 'app/helpers/workhorse_helper.rb', line 63

def content_disposition_for_blob(blob, inline)
  return 'inline' if inline

  ActionDispatch::Http::ContentDisposition.format(disposition: 'attachment', filename: blob.name)
end

#send_artifacts_entry(file, entry) ⇒ Object

Send an entry from artifacts through Workhorse and set safe content type



39
40
41
42
43
44
# File 'app/helpers/workhorse_helper.rb', line 39

def send_artifacts_entry(file, entry)
  headers.store(*Gitlab::Workhorse.send_artifacts_entry(file, entry))
  headers.store(*Gitlab::Workhorse.detect_content_type)

  head :ok
end

#send_dependency(dependency_headers, url, filename) ⇒ Object



46
47
48
49
50
51
52
53
# File 'app/helpers/workhorse_helper.rb', line 46

def send_dependency(dependency_headers, url, filename)
  headers.store(*Gitlab::Workhorse.send_dependency(dependency_headers, url))
  headers['Content-Disposition'] =
    ActionDispatch::Http::ContentDisposition.format(disposition: 'attachment', filename: filename)
  headers['Content-Type'] = 'application/gzip'

  head :ok
end

#send_git_archive(repository, **kwargs) ⇒ Object

Archive a Git repository and send it through Workhorse



33
34
35
36
# File 'app/helpers/workhorse_helper.rb', line 33

def send_git_archive(repository, **kwargs)
  headers.store(*Gitlab::Workhorse.send_git_archive(repository, **kwargs))
  head :ok
end

#send_git_blob(repository, blob, inline: true) ⇒ Object

Send a Git blob through Workhorse



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/workhorse_helper.rb', line 7

def send_git_blob(repository, blob, inline: true)
  headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))

  headers['Content-Disposition'] = content_disposition_for_blob(blob, inline)

  # If enabled, this will override the values set above
  workhorse_set_content_type!

  render plain: ""
end

#send_git_diff(repository, diff_refs) ⇒ Object

Send a Git diff through Workhorse



19
20
21
22
23
# File 'app/helpers/workhorse_helper.rb', line 19

def send_git_diff(repository, diff_refs)
  headers.store(*Gitlab::Workhorse.send_git_diff(repository, diff_refs))
  headers['Content-Disposition'] = 'inline'
  head :ok
end

#send_git_patch(repository, diff_refs) ⇒ Object

Send a Git patch through Workhorse



26
27
28
29
30
# File 'app/helpers/workhorse_helper.rb', line 26

def send_git_patch(repository, diff_refs)
  headers.store(*Gitlab::Workhorse.send_git_patch(repository, diff_refs))
  headers['Content-Disposition'] = 'inline'
  head :ok
end

#set_workhorse_internal_api_content_typeObject



55
56
57
# File 'app/helpers/workhorse_helper.rb', line 55

def set_workhorse_internal_api_content_type
  headers['Content-Type'] = Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE
end

#workhorse_set_content_type!Object



59
60
61
# File 'app/helpers/workhorse_helper.rb', line 59

def workhorse_set_content_type!
  headers[Gitlab::Workhorse::DETECT_HEADER] = "true"
end