From 6bb3cd08c635fe23ffebd11721c8ddd1399438ab Mon Sep 17 00:00:00 2001 From: Chris Frohoff Date: Fri, 9 Aug 2013 15:53:06 -0700 Subject: [PATCH 1/7] fix for logging error with urls containing "%" --- lib/restclient/request.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 1dd5267..15eb5a8 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -215,11 +215,11 @@ module RestClient size += chunk.size if RestClient.log if size == 0 - RestClient.log << "#{@method} #{@url} done (0 length file\n)" + RestClient.log << "%s %s done (0 length file\n)" % [@method, @url] elsif total == 0 - RestClient.log << "#{@method} #{@url} (zero content length)\n" + RestClient.log << "%s %s (zero content length)\n" % [@method, @url] else - RestClient.log << "#{@method} #{@url} %d%% done (%d of %d)\n" % [(size * 100) / total, size, total] + RestClient.log << "%s %s %d%% done (%d of %d)\n" % [@method, @url, (size * 100) / total, size, total] end end end From eaa1723fba236e0feed7fe46491fd4071f132cfb Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Wed, 12 Mar 2014 17:57:17 -0700 Subject: [PATCH 2/7] Use git ls-files -z to be safer with filenames. Not that anyone will add filenames with weird characters, but we may as well be safe. --- rest-client.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest-client.gemspec b/rest-client.gemspec index e9a6acc..51062ea 100644 --- a/rest-client.gemspec +++ b/rest-client.gemspec @@ -11,8 +11,8 @@ Gem::Specification.new do |s| s.email = 'rest.client@librelist.com' s.executables = ['restclient'] s.extra_rdoc_files = ["README.rdoc", "history.md"] - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- spec/*`.split("\n") + s.files = `git ls-files -z`.split("\0") + s.test_files = `git ls-files -z -- spec/*`.split("\0") s.homepage = 'http://github.com/rest-client/rest-client' s.summary = 'Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.' From 4620ad254d2768e5e6c1bb485b817cb0fa9e67ce Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Wed, 12 Mar 2014 18:03:14 -0700 Subject: [PATCH 3/7] Use single quotes where possible. --- rest-client.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest-client.gemspec b/rest-client.gemspec index 51062ea..05e8566 100644 --- a/rest-client.gemspec +++ b/rest-client.gemspec @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- -require File.expand_path("../lib/restclient/version", __FILE__) +require File.expand_path('../lib/restclient/version', __FILE__) Gem::Specification.new do |s| s.name = 'rest-client' @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.license = 'MIT' s.email = 'rest.client@librelist.com' s.executables = ['restclient'] - s.extra_rdoc_files = ["README.rdoc", "history.md"] + s.extra_rdoc_files = ['README.rdoc', 'history.md'] s.files = `git ls-files -z`.split("\0") s.test_files = `git ls-files -z -- spec/*`.split("\0") s.homepage = 'http://github.com/rest-client/rest-client' From 0dca1579008f492e0195386449c239ce74ac018a Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Fri, 28 Mar 2014 02:18:41 -0700 Subject: [PATCH 4/7] Drop the Net::HTTP::Patch monkey patch. Now that we require Ruby >= 1.9.3, there's no need for this monkey patch. --- lib/restclient/net_http_ext.rb | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/lib/restclient/net_http_ext.rb b/lib/restclient/net_http_ext.rb index d34f1e4..94c5222 100644 --- a/lib/restclient/net_http_ext.rb +++ b/lib/restclient/net_http_ext.rb @@ -1,39 +1,5 @@ module Net class HTTP - - # Adding the patch method if it doesn't exist (rest-client issue: https://github.com/archiloque/rest-client/issues/79) - if !defined?(Net::HTTP::Patch) - # Code taken from this commit: https://github.com/ruby/ruby/commit/ab70e53ac3b5102d4ecbe8f38d4f76afad29d37d#lib/net/http.rb - class Protocol - # Sends a PATCH request to the +path+ and gets a response, - # as an HTTPResponse object. - def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+ - send_entity(path, data, initheader, dest, Patch, &block) - end - - # Executes a request which uses a representation - # and returns its body. - def send_entity(path, data, initheader, dest, type, &block) - res = nil - request(type.new(path, initheader), data) {|r| - r.read_body dest, &block - res = r - } - unless @newimpl - res.value - return res, res.body - end - res - end - end - - class Patch < HTTPRequest - METHOD = 'PATCH' - REQUEST_HAS_BODY = true - RESPONSE_HAS_BODY = true - end - end - # # Replace the request method in Net::HTTP to sniff the body type # and set the stream if appropriate From 5eb961881421e82810f227250851d05c8e6c5db6 Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Fri, 28 Mar 2014 02:53:58 -0700 Subject: [PATCH 5/7] Tweak indentation. --- lib/restclient/request.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 8503a83..5e02739 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -361,9 +361,10 @@ module RestClient end private - def parser - URI.const_defined?(:Parser) ? URI::Parser.new : URI - end + + def parser + URI.const_defined?(:Parser) ? URI::Parser.new : URI + end end end From 43c08e587993a564ca5eaa4e4a286c339ccf2906 Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Fri, 28 Mar 2014 02:54:09 -0700 Subject: [PATCH 6/7] There was no good reason for this monkey patch. --- lib/restclient.rb | 1 - lib/restclient/net_http_ext.rb | 21 --------------------- lib/restclient/request.rb | 16 ++++++++++++++-- 3 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 lib/restclient/net_http_ext.rb diff --git a/lib/restclient.rb b/lib/restclient.rb index 939cf39..908bc07 100644 --- a/lib/restclient.rb +++ b/lib/restclient.rb @@ -17,7 +17,6 @@ require File.dirname(__FILE__) + '/restclient/response' require File.dirname(__FILE__) + '/restclient/raw_response' require File.dirname(__FILE__) + '/restclient/resource' require File.dirname(__FILE__) + '/restclient/payload' -require File.dirname(__FILE__) + '/restclient/net_http_ext' # This module's static methods are the entry point for using the REST client. # diff --git a/lib/restclient/net_http_ext.rb b/lib/restclient/net_http_ext.rb deleted file mode 100644 index 94c5222..0000000 --- a/lib/restclient/net_http_ext.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Net - class HTTP - # - # Replace the request method in Net::HTTP to sniff the body type - # and set the stream if appropriate - # - # Taken from: - # http://www.missiondata.com/blog/ruby/29/streaming-data-to-s3-with-ruby/ - - alias __request__ request - - def request(req, body=nil, &block) - if body != nil && body.respond_to?(:read) - req.body_stream = body - return __request__(req, nil, &block) - else - return __request__(req, body, &block) - end - end - end -end diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 5e02739..0d502e5 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -150,6 +150,15 @@ module RestClient Net::HTTP.const_get(method.to_s.capitalize) end + def net_http_do_request(http, req, body=nil, &block) + if body != nil && body.respond_to?(:read) + req.body_stream = body + return http.request(req, nil, &block) + else + return http.request(req, body, &block) + end + end + def parse_url(url) url = "http://#{url}" unless url.match(/^http/) URI.parse(url) @@ -227,11 +236,14 @@ module RestClient log_request + net.start do |http| if @block_response - http.request(req, payload ? payload.to_s : nil, & @block_response) + net_http_do_request(http, req, payload ? payload.to_s : nil, + & @block_response) else - res = http.request(req, payload ? payload.to_s : nil) { |http_response| fetch_body(http_response) } + res = net_http_do_request(http, req, payload ? payload.to_s : nil) \ + { |http_response| fetch_body(http_response) } log_response res process_result res, & block end From 0037bf373b26c6c644e44bd65842b096173ed84d Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Fri, 28 Mar 2014 12:28:01 -0700 Subject: [PATCH 7/7] Add a license file. The MIT license was previously incorporated by reference in the README, but it's recommended to include the license text to avoid ambiguity. https://help.github.com/articles/open-source-licensing --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3e84989 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2008-2014 Rest Client Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.