mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
tweaked the way base uri works and set https to not verify so we don't get warnings
This commit is contained in:
parent
473325dfd4
commit
a8e1e6acbd
1 changed files with 7 additions and 1 deletions
|
@ -19,6 +19,8 @@ module Web
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def base_uri(base_uri=nil)
|
def base_uri(base_uri=nil)
|
||||||
return @base_uri unless base_uri
|
return @base_uri unless base_uri
|
||||||
|
# don't want this to ever end with /
|
||||||
|
base_uri = base_uri.ends_with?('/') ? base_uri.chop : base_uri
|
||||||
@base_uri = ensure_http(base_uri)
|
@base_uri = ensure_http(base_uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,6 +33,8 @@ module Web
|
||||||
uri = URI.parse(base_uri)
|
uri = URI.parse(base_uri)
|
||||||
@http = Net::HTTP.new(uri.host, uri.port)
|
@http = Net::HTTP.new(uri.host, uri.port)
|
||||||
@http.use_ssl = (uri.port == 443)
|
@http.use_ssl = (uri.port == 443)
|
||||||
|
# so we can avoid ssl warnings
|
||||||
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
end
|
end
|
||||||
@http
|
@http
|
||||||
end
|
end
|
||||||
|
@ -70,8 +74,10 @@ module Web
|
||||||
# body => string for raw post data
|
# body => string for raw post data
|
||||||
# headers => hash of headers to send request with
|
# headers => hash of headers to send request with
|
||||||
def send_request(method, path, options={})
|
def send_request(method, path, options={})
|
||||||
|
# we always want path that begins with /
|
||||||
|
path = path.starts_with?('/') ? path : "/#{path}"
|
||||||
@format = format_from_path(path) unless @format
|
@format = format_from_path(path) unless @format
|
||||||
uri = URI.join(base_uri, path)
|
uri = URI.parse("#{base_uri}#{path}")
|
||||||
uri.query = options[:query].to_query unless options[:query].blank?
|
uri.query = options[:query].to_query unless options[:query].blank?
|
||||||
klass = Net::HTTP.const_get method.to_s.downcase.capitalize
|
klass = Net::HTTP.const_get method.to_s.downcase.capitalize
|
||||||
request = klass.new(uri.request_uri)
|
request = klass.new(uri.request_uri)
|
||||||
|
|
Loading…
Reference in a new issue