Class: Gitlab::Experiment::Middleware

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, base_path) ⇒ Middleware

Returns a new instance of Middleware.



13
14
15
16
# File 'lib/gitlab/experiment/middleware.rb', line 13

def initialize(app, base_path)
  @app = app
  @matcher = %r{^#{base_path}/(?<id>.+)}
end

Class Method Details

.redirect(id, url) ⇒ Object

Raises:



6
7
8
9
10
11
# File 'lib/gitlab/experiment/middleware.rb', line 6

def self.redirect(id, url)
  raise Error, 'no url to redirect to' if url.blank?

  experiment = Gitlab::Experiment.from_param(id)
  [303, { 'Location' => experiment.process_redirect_url(url) || raise(Error, 'not redirecting') }, []]
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/gitlab/experiment/middleware.rb', line 18

def call(env)
  return @app.call(env) if env['REQUEST_METHOD'] != 'GET' || (match = @matcher.match(env['PATH_INFO'])).nil?

  Middleware.redirect(match[:id], env['QUERY_STRING'])
rescue Error
  @app.call(env)
end