Class: Workarea::StripHttpCachingMiddleware

Inherits:
Object
  • Object
show all
Defined in:
app/middleware/workarea/strip_http_caching_middleware.rb

Overview

This class exists to disable all HTTP caching in the test envionrment. There’s no way to disable caching in headless Chrome so this ensures reliability with running tests there.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ StripHttpCachingMiddleware

Returns a new instance of StripHttpCachingMiddleware.



6
7
8
# File 'app/middleware/workarea/strip_http_caching_middleware.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/middleware/workarea/strip_http_caching_middleware.rb', line 10

def call(env)
  status, headers, body = @app.call(env)

  unless Workarea.config.strip_http_caching_in_tests
    return [status, headers, body]
  end

  headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
  headers['Expires'] = '0'

  [status, headers, body]
end