Class: Gitlab::Testing::RobotsBlockerMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/testing/robots_blocker_middleware.rb

Constant Summary collapse

@@block_requests =
Concurrent::AtomicBoolean.new(false)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RobotsBlockerMiddleware

Returns a new instance of RobotsBlockerMiddleware.



20
21
22
# File 'lib/gitlab/testing/robots_blocker_middleware.rb', line 20

def initialize(app)
  @app = app
end

Class Method Details

.allow_requests!Object

Allows the server to accept requests again.



16
17
18
# File 'lib/gitlab/testing/robots_blocker_middleware.rb', line 16

def self.allow_requests!
  @@block_requests.value = false
end

.block_requests!Object

Block requests according to robots.txt. Any new requests disallowed by robots.txt will return an HTTP 503 status.



11
12
13
# File 'lib/gitlab/testing/robots_blocker_middleware.rb', line 11

def self.block_requests!
  @@block_requests.value = true
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/testing/robots_blocker_middleware.rb', line 24

def call(env)
  request = Rack::Request.new(env)

  if block_requests? && Gitlab::RobotsTxt.disallowed?(request.path_info)
    block_request(env)
  else
    @app.call(env)
  end
end