Last active
December 19, 2015 12:09
-
-
Save srawlins/5953328 to your computer and use it in GitHub Desktop.
Example of rack #571
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'stringio' | |
| require 'zlib' | |
| GZ_FILE = "rack-issue-571.gz" | |
| class VerboseStringIO < StringIO | |
| attr_accessor :log | |
| def initialize(*args) | |
| @log = [] | |
| super | |
| end | |
| def write(input) | |
| STDOUT.puts "input: #{input.inspect}" | |
| STDOUT.puts "@log before <<: #{@log.inspect}" | |
| @log << input | |
| super | |
| STDOUT.puts "@log after <<: #{@log.inspect}\n\n" | |
| end | |
| end | |
| string_io = VerboseStringIO.new() | |
| gzw = Zlib::GzipWriter.new(string_io) | |
| gzw.write("hello\n"); gzw.flush | |
| gzw.write("there\n"); gzw.flush | |
| gzw.close | |
| # Write out our log of what was "written" to one IO-like thing, | |
| # to another IO-like thing | |
| File.open(GZ_FILE, "w") { |handle| handle.write string_io.log.join } | |
| Zlib::GzipReader.open(GZ_FILE) { |gzr| print gzr.read } | |
| File.unlink(GZ_FILE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| s@sd ~/code$ ruby -v | |
| jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK Server VM 1.7.0 [linux-i386] | |
| s@sd ~/code$ ruby jruby-test.rb | |
| input: "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\xFF" | |
| @log before <<: [] | |
| @log after <<: ["\x1F\x8B\b\x00\x00\x00\x00\x00\x00\xFF"] | |
| input: "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF" | |
| @log before <<: ["\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00"] | |
| @log after <<: ["\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00", "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF"] | |
| input: "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF" | |
| @log before <<: ["*\xC9H-J\xE5\x02\x00\x00\x00", "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF"] | |
| @log after <<: ["*\xC9H-J\xE5\x02\x00\x00\x00", "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF", "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF"] | |
| input: "\x03\x00\\#\x1C2\f\x00\x00\x00" | |
| @log before <<: ["\x03\x00\\#\x1C2\f\x00\x00\x00", "\x03\x00\\#\x1C2\f\x00\x00\x00\xFF\xFF", "\x03\x00\\#\x1C2\f\x00\x00\x00\xFF\xFF"] | |
| @log after <<: ["\x03\x00\\#\x1C2\f\x00\x00\x00", "\x03\x00\\#\x1C2\f\x00\x00\x00\xFF\xFF", "\x03\x00\\#\x1C2\f\x00\x00\x00\xFF\xFF", "\x03\x00\\#\x1C2\f\x00\x00\x00"] | |
| Zlib::GzipFile::Error: not in gzip format | |
| initialize at org/jruby/ext/zlib/JZlibRubyGzipReader.java:110 | |
| new at org/jruby/ext/zlib/JZlibRubyGzipReader.java:56 | |
| open at org/jruby/ext/zlib/JZlibRubyGzipReader.java:72 | |
| (root) at jruby-test.rb:33 | |
| s@sd ~/code$ ruby -v | |
| ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] | |
| s@sd ~/code$ ruby jruby-test.rb | |
| input: "\x1F\x8B\b\x00>I\xDBQ\x00\x03" | |
| @log before <<: [] | |
| @log after <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03"] | |
| input: "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF" | |
| @log before <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03"] | |
| @log after <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03", "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF"] | |
| input: "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF" | |
| @log before <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03", "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF"] | |
| @log after <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03", "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF", "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF"] | |
| input: "\x03\x00\\#\x1C2\f\x00\x00\x00" | |
| @log before <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03", "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF", "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF"] | |
| @log after <<: ["\x1F\x8B\b\x00>I\xDBQ\x00\x03", "\xCAH\xCD\xC9\xC9\xE7\x02\x00\x00\x00\xFF\xFF", "*\xC9H-J\xE5\x02\x00\x00\x00\xFF\xFF", "\x03\x00\\#\x1C2\f\x00\x00\x00"] | |
| hello | |
| there |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment