Sha256: ebc8790a2b5d187d8c934aff3a4beb9dab896c71c3230b009b392fdaff7fc5d6

Contents?: true

Size: 928 Bytes

Versions: 19

Compression:

Stored size: 928 Bytes

Contents

module Shipit
  class StripCacheControl < Faraday::Middleware
    def call(request_env)
      @app.call(request_env).on_complete do |response_env|
        if headers = response_env[:response_headers]
          headers.delete('last-modified')
          directives = parse(headers['cache-control'].to_s)
          directives.delete('max-age')
          directives.delete('s-maxage')
          headers['cache-control'] = dump(directives)
        end
      end
    end

    private

    def dump(directives)
      directives.map do |k, v|
        if v == true
          k
        else
          "#{k}=#{v}"
        end
      end.join(', ')
    end

    def parse(header)
      directives = {}

      header.delete(' ').split(',').each do |part|
        next if part.empty?

        name, value = part.split('=', 2)
        directives[name.downcase] = (value || true) unless name.empty?
      end

      directives
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
shipit-engine-0.28.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.27.1 lib/shipit/strip_cache_control.rb
shipit-engine-0.27.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.26.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.25.1 lib/shipit/strip_cache_control.rb
shipit-engine-0.25.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.24.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.23.1 lib/shipit/strip_cache_control.rb
shipit-engine-0.23.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.22.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.21.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.20.1 lib/shipit/strip_cache_control.rb
shipit-engine-0.20.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.19.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.18.1 lib/shipit/strip_cache_control.rb
shipit-engine-0.18.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.17.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.16.0 lib/shipit/strip_cache_control.rb
shipit-engine-0.15.0 lib/shipit/strip_cache_control.rb