spec/support/test_server.rb in patron-0.5.1 vs spec/support/test_server.rb in patron-0.6.0

- old
+ new

@@ -68,10 +68,33 @@ def do_COPY(req,res) respond_with(:COPY, req, res) end end +class GzipServlet < HTTPServlet::AbstractServlet + + def do_GET(req,res) + raise "Need to have the right Accept-Encoding: header" unless req.header['Accept-Encoding'] + + out = StringIO.new + z = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION) + 1024.times { + out << z.deflate('Some highly compressible data') + } + out << z.finish + z.close + + content_length = out.size + # Content-Length gets set automatically by WEBrick, and if we do it manually + # here then two headers will be set. + # res.header['Content-Length'] = content_length + res.header['Content-Encoding'] = 'deflate' + res.header['Vary'] = 'Accept-Encoding' + res.body = out.string + end +end + class TimeoutServlet < HTTPServlet::AbstractServlet def do_GET(req,res) sleep(1.1) end end @@ -81,20 +104,17 @@ res['Location'] = "http://localhost:9001/test" res.status = 301 end end - class TestPostBodyServlet < HTTPServlet::AbstractServlet include RespondWith def do_POST(req, res) respond_with(:POST, {'body' => req.body, 'content_type' => req.content_type}, res) end end - - class SetCookieServlet < HTTPServlet::AbstractServlet def do_GET(req, res) res['Set-Cookie'] = "session_id=foo123" res['Location'] = "http://localhost:9001/test" res.status = 301 @@ -160,9 +180,10 @@ @server.mount("/redirect", RedirectServlet) @server.mount("/picture", PictureServlet) @server.mount("/setcookie", SetCookieServlet) @server.mount("/repetitiveheader", RepetitiveHeaderServlet) @server.mount("/wrongcontentlength", WrongContentLengthServlet) + @server.mount("/gzip-compressed", GzipServlet) end def start trap('INT') {