lib/knj/http2.rb in knjrbfw-0.0.35 vs lib/knj/http2.rb in knjrbfw-0.0.36

- old
+ new

@@ -1,8 +1,5 @@ -require "#{$knjpath}web" -require "socket" - #This class tries to emulate a browser in Ruby without any visual stuff. Remember cookies, keep sessions alive, reset connections according to keep-alive rules and more. #===Examples # Knj::Http2.new(:host => "www.somedomain.com", :port => 80, :ssl => false, :debug => false) do |http| # res = http.get("index.rhtml?show=some_page") # html = res.body @@ -14,10 +11,12 @@ # end class Knj::Http2 attr_reader :cookies, :args def initialize(args = {}) + require "#{$knjpath}web" + args = {:host => args} if args.is_a?(String) raise "Arguments wasnt a hash." if !args.is_a?(Hash) @args = args @cookies = {} @@ -97,10 +96,11 @@ @sock_ssl = nil end #Reconnects to the host. def reconnect + require "socket" print "Http2: Reconnect.\n" if @debug #Reset variables. @keepalive_max = nil @keepalive_timeout = nil @@ -270,16 +270,16 @@ pdata.each do |key, val| praw << "--#{boundary}#{@nl}" if val.class.name == "Tempfile" and val.respond_to?("original_filename") praw << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{val.original_filename}\";#{@nl}" - praw << "Content-Length: #{val.bytesize}#{@nl}" + praw << "Content-Length: #{val.to_s.bytesize}#{@nl}" elsif val.is_a?(Hash) and val[:filename] praw << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{val[:filename]}\";#{@nl}" - praw << "Content-Length: #{val[:content].bytesize}#{@nl}" + praw << "Content-Length: #{val[:content].to_s.bytesize}#{@nl}" else praw << "Content-Disposition: form-data; name=\"#{key}\";#{@nl}" - praw << "Content-Length: #{val.bytesize}#{@nl}" + praw << "Content-Length: #{val.to_s.bytesize}#{@nl}" end praw << "Content-Type: text/plain#{@nl}" praw << @nl \ No newline at end of file