2012-09-12 5 views
8

Heroku'da garip bir hata var. Yeniden üretebilmek için istek gövdesinde herhangi bir UTF-8 karakteriyle büyük (birkaç KB üzeri) HTTPS POST yapmam gerekiyor. İşte bir örnek: 'Heroku konsolunda' üzerine koşuyoruz, beklenen'EOFError: UTU-8 üzerinden UTF-8 gönderilirken HEROKU'da dosya sonuna ulaşıldı

#<Net::HTTPUnauthorized 401 Unauthorized readbody=true> 

... ama Heroku sedir üzerinde ..:

require "net/https" 
require "uri" 

#Accutally I've ecountered this bug while posting to another server 
url = URI.parse("https://api.heroku.com/myapps") 

#It's Ukrainian 'oiced velar plosive G' letter 
payload = "ґ"*10000 
request = Net::HTTP::Post.new(url.path) 
request.body = payload 
http = Net::HTTP.new(url.host, url.port) 
http.use_ssl = true 
http.read_timeout = 500 
http.start {|http| http.request request } 

yerel makinenin irb böyle senaryoyu Koşu bana verir Yaklaşık 60sn'de:

EOFError: end of file reached 
    from /usr/local/lib/ruby/1.9.1/openssl/buffering.rb:145:in `sysread_nonblock' 
    from /usr/local/lib/ruby/1.9.1/openssl/buffering.rb:145:in `read_nonblock' 
    from /usr/local/lib/ruby/1.9.1/net/protocol.rb:135:in `rbuf_fill' 
    from /usr/local/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil' 
    from /usr/local/lib/ruby/1.9.1/net/protocol.rb:126:in `readline' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:2208:in `read_new' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:1177:in `request' 
    from (irb):32:in `block in irb_binding' 
    from /usr/local/lib/ruby/1.9.1/net/http.rb:627:in `start' 
    from (irb):32 
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.7/lib/rails/commands/console.rb:47:in `start' 
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.7/lib/rails/commands/console.rb:8:in `start' 
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.7/lib/rails/commands.rb:41:in `<top (required)>' 

Bununla ne yapmalıyım?

cevap

3

varsayılan sedir'ın yakut 1.9.2 olduğu gibi, Gemfile içine yakut versiyonunu eklemek zorunda (ki SSL üzerinden UTF-8 dizeleri hata geçen vardır)

source 'https://rubygems.org' 
ruby "1.9.3" 

gem 'rails', '3.2.7' 
gem 'pg' 
... 
2

Bence, bu should çalışır:

require "net/https" 
require "uri" 

url = URI.parse("https://api.heroku.com/myapps") 
#It's Ukrainian letter 'soft-G' 
payload = "ґ"*10000 
request = Net::HTTP::Post.new(url.path) 
request.basic_auth 'youremail', 'yourpassword' 
request.body = URI.encode(payload) 
http = Net::HTTP.new(url.host, url.port) 
http.use_ssl = true 
http.read_timeout = 500 
http.start {|http| http.request request }