class KramdownRFC::KDRFC
def run_idnits_remotely(txt_fn)
def run_idnits_remotely(txt_fn) url = URI(IDNITS_WEBSERVICE) req = Net::HTTP::Post.new(url) form = [["file", File.open(txt_fn), {filename: "input.txt", content_type: "text/plain"}], ["hidetext", "true"]] diag = ["url/form: ", url, form].inspect req.set_form(form, 'multipart/form-data') warn "* requesting idnits at #{url}" if @options.verbose t0 = Time.now res = persistent_http.request(url, req) warn "* elapsed time: #{Time.now - t0}" if @options.verbose case res when Net::HTTPBadRequest result = checked_json(res.body) raise IOError.new("*** Remote Error: #{result["error"]}") when Net::HTTPOK case res.content_type when 'text/plain' if res.body == '' raise IOError.new("*** HTTP response is empty with status #{res.code}, not written") end puts res.body else warning = "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}, #{diag}" warning << "\n" warning << res.body raise IOError.new(warning) end else raise IOError.new("*** HTTP response: #{res.code}, #{diag}") end end