Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Additional change for the previous commit; do hexdump if a content lo…

…oks binary.
  • Loading branch information...
commit d5f00101b96d9378bc82701afeb6c7ad2c35ac5c 1 parent cfc2abc
@nahi authored
Showing with 41 additions and 2 deletions.
  1. +1 −0  install.rb
  2. +36 −0 lib/hexdump.rb
  3. +4 −2 lib/httpclient/session.rb
View
1  install.rb
@@ -36,6 +36,7 @@ def install(*path)
begin
install('httpclient.rb')
install('oauthclient.rb')
+ install('hexdump.rb')
install('httpclient')
install('httpclient', 'cacert.p7s')
install('http-access2.rb')
View
36 lib/hexdump.rb
@@ -0,0 +1,36 @@
+# This was written by Arai-san and published at
+# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/31987
+
+
+module HexDump
+ def encode(str)
+ offset = 0
+ result = []
+ while raw = str.slice(offset, 16) and raw.length > 0
+ # data field
+ data = ''
+ for v in raw.unpack('N* a*')
+ if v.kind_of? Integer
+ data << sprintf("%08x ", v)
+ else
+ v.each_byte {|c| data << sprintf("%02x", c) }
+ end
+ end
+ # text field
+ text = raw.tr("\000-\037\177-\377", ".")
+ result << sprintf("%08x %-36s %s", offset, data, text)
+ offset += 16
+ # omit duplicate line
+ if /^(#{ Regexp.quote(raw) })+/n =~ str[offset .. -1]
+ result << sprintf("%08x ...", offset)
+ offset += $&.length
+ # should print at the end
+ if offset == str.length
+ result << sprintf("%08x %-36s %s", offset-16, data, text)
+ end
+ end
+ end
+ result
+ end
+ module_function :encode
+end
View
6 lib/httpclient/session.rb
@@ -436,8 +436,10 @@ def <<(str)
def debug(str)
if str && @debug_dev
- if str.include? "\0" then
- @debug_dev << "#{str.length} bytes of possible binary data\n"
+ if str.index("\0")
+ require 'hexdump'
+ str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
+ @debug_dev << HexDump.encode(str).join("\n")
else
@debug_dev << str
end
Please sign in to comment.
Something went wrong with that request. Please try again.