mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Merge branch 'master' into ab-ssl
Conflicts: lib/restclient.rb rest-client.gemspec
This commit is contained in:
commit
c5f5415b4e
5 changed files with 44 additions and 66 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
|
@ -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'
|
||||
require File.dirname(__FILE__) + '/restclient/windows'
|
||||
|
||||
# This module's static methods are the entry point for using the REST client.
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
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
|
||||
#
|
||||
# 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
|
|
@ -262,6 +262,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)
|
||||
|
@ -372,11 +381,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
|
||||
|
@ -410,11 +422,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
|
||||
|
@ -506,6 +518,7 @@ module RestClient
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
def parser
|
||||
URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
||||
end
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue