Class: Gitlab::Middleware::Multipart

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/middleware/multipart.rb

Defined Under Namespace

Classes: Handler

Constant Summary collapse

RACK_ENV_KEY =
'HTTP_GITLAB_WORKHORSE_MULTIPART_FIELDS'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Multipart

Returns a new instance of Multipart.


136
137
138
# File 'lib/gitlab/middleware/multipart.rb', line 136

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/gitlab/middleware/multipart.rb', line 140

def call(env)
  encoded_message = env.delete(RACK_ENV_KEY)
  return @app.call(env) if encoded_message.blank?

  message = ::Gitlab::Workhorse.decode_jwt(encoded_message)[0]

  ::Gitlab::Middleware::Multipart::Handler.new(env, message).with_open_files do
    @app.call(env)
  end
rescue UploadedFile::InvalidPathError => e
  [400, { 'Content-Type' => 'text/plain' }, e.message]
end