Sha256: 6c54b3bf88cbb0055ecb3f325dae30fac5abebbf749a6d6c25d3cb57f6943e8a

Contents?: true

Size: 770 Bytes

Versions: 14

Compression:

Stored size: 770 Bytes

Contents

require 'stringio'
require 'zlib'

class GzipServlet < WEBrick::HTTPServlet::AbstractServlet

  TEST_DIR = File.expand_path '../../../../test', __FILE__

  def do_GET(req, res)
    if req['Accept-Encoding'] !~ /gzip/ then
      res.code = 400
      res.body = 'Content-Encoding: gzip is not supported by your user-agent'
      return
    end

    if name = req.query['file'] then
      open "#{TEST_DIR}/htdocs/#{name}" do |io|
        string = ""
        zipped = StringIO.new string, 'w'
        Zlib::GzipWriter.wrap zipped do |gz|
          gz.write io.read
        end
        res.body = string
      end
    else
      res.body = ''
    end

    res['Content-Encoding'] = req['X-ResponseContentEncoding'] || 'gzip'
    res['Content-Type'] = "text/html"
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
husc-0.2.1 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/test_case/gzip_servlet.rb
husc-0.2.0 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/test_case/gzip_servlet.rb
husc-0.1.1 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/test_case/gzip_servlet.rb
husc-0.1.0 vendor/bundle/gems/mechanize-2.7.6/lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.6 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.5 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.4 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.3 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.2 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.1 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.7.0 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.6.0 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.5.1 lib/mechanize/test_case/gzip_servlet.rb
mechanize-2.5 lib/mechanize/test_case/gzip_servlet.rb