From b4bca0bc9af128016efa42adaee0ea106ab54def Mon Sep 17 00:00:00 2001 From: shao1555 Date: Mon, 18 Dec 2017 15:33:48 +0900 Subject: [PATCH 1/2] add batch support for http client --- lib/ethereum/http_client.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ethereum/http_client.rb b/lib/ethereum/http_client.rb index b8a214d..b2244eb 100644 --- a/lib/ethereum/http_client.rb +++ b/lib/ethereum/http_client.rb @@ -28,7 +28,12 @@ def send_single(payload) end def send_batch(batch) - raise NotImplementedError + result = send_single(batch.to_json) + result = JSON.parse(result) + + # Make sure the order is the same as it was when batching calls + # See 6 Batch here http://www.jsonrpc.org/specification + return result.sort_by! { |c| c['id'] } end end From af9830a350fbd16f38ceedd8944460d022db6587 Mon Sep 17 00:00:00 2001 From: shao1555 Date: Wed, 21 Feb 2018 18:39:55 +0900 Subject: [PATCH 2/2] added cookie support --- lib/ethereum/http_client.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/ethereum/http_client.rb b/lib/ethereum/http_client.rb index b2244eb..bf8e869 100644 --- a/lib/ethereum/http_client.rb +++ b/lib/ethereum/http_client.rb @@ -1,13 +1,15 @@ require 'net/http' module Ethereum class HttpClient < Client - attr_accessor :host, :port, :uri, :ssl + attr_accessor :host, :port, :uri, :ssl, :cookie - def initialize(host, port, ssl = false, log = false) + def initialize(host, port, ssl = false, log = false, cookie = false) super(log) @host = host @port = port @ssl = ssl + @use_cookie = cookie + @cookie = nil if ssl @uri = URI("https://#{@host}:#{@port}") else @@ -21,9 +23,18 @@ def send_single(payload) http.use_ssl = true end header = {'Content-Type' => 'application/json'} + if @use_cookie && @cookie.present? + header['Cookie'] = @cookie + end request = ::Net::HTTP::Post.new(uri, header) request.body = payload response = http.request(request) + if @use_cookie + set_cookie_headers = response.get_fields('set-cookie') + if set_cookie_headers.present? + @cookie = set_cookie_headers.map{|str| str.split('; ').first}.join('; ') + end + end return response.body end