Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Vendorize "uri" library
Browse files Browse the repository at this point in the history
We vendorize it as a dependency of `net-http-persistent`, so usages
inside `net-http-persistent` get automatically replaced by `automatiek`.
  • Loading branch information
deivid-rodriguez committed Dec 8, 2019
1 parent 0490f16 commit 8f80bda
Show file tree
Hide file tree
Showing 16 changed files with 4,179 additions and 26 deletions.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ else
sublib.prefix = "Bundler"
sublib.vendor_lib = "lib/bundler/vendor/connection_pool"
end

lib.dependency("uri") do |sublib|
sublib.version = "master"
sublib.download = { :github => "https://github.com/ruby/uri" }
sublib.namespace = "URI"
sublib.prefix = "Bundler"
sublib.vendor_lib = "lib/bundler/vendor/uri"
end
end
end

Expand Down
52 changes: 26 additions & 26 deletions lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'net/http'
require 'uri'
require_relative '../../../../uri/lib/uri'
require 'cgi' # for escaping
require_relative '../../../../connection_pool/lib/connection_pool'

Expand Down Expand Up @@ -31,7 +31,7 @@
#
# require 'bundler/vendor/net-http-persistent/lib/net/http/persistent'
#
# uri = URI 'http://example.com/awesome/web/service'
# uri = Bundler::URI 'http://example.com/awesome/web/service'
#
# http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name'
#
Expand All @@ -48,17 +48,17 @@
# post = Net::HTTP::Post.new post_uri.path
# post.set_form_data 'some' => 'cool data'
#
# # perform the POST, the URI is always required
# # perform the POST, the Bundler::URI is always required
# response http.request post_uri, post
#
# Note that for GET, HEAD and other requests that do not have a body you want
# to use URI#request_uri not URI#path. The request_uri contains the query
# to use Bundler::URI#request_uri not Bundler::URI#path. The request_uri contains the query
# params which are sent in the body for other requests.
#
# == SSL
#
# SSL connections are automatically created depending upon the scheme of the
# URI. SSL connections are automatically verified against the default
# Bundler::URI. SSL connections are automatically verified against the default
# certificate store for your computer. You can override this by changing
# verify_mode or by specifying an alternate cert_store.
#
Expand All @@ -81,7 +81,7 @@
# == Proxies
#
# A proxy can be set through #proxy= or at initialization time by providing a
# second argument to ::new. The proxy may be the URI of the proxy server or
# second argument to ::new. The proxy may be the Bundler::URI of the proxy server or
# <code>:ENV</code> which will consult environment variables.
#
# See #proxy= and #proxy_from_env for details.
Expand Down Expand Up @@ -150,7 +150,7 @@
#
# require 'bundler/vendor/net-http-persistent/lib/net/http/persistent'
#
# uri = URI 'http://example.com/awesome/web/service'
# uri = Bundler::URI 'http://example.com/awesome/web/service'
# post_uri = uri + 'create'
#
# http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name'
Expand Down Expand Up @@ -249,7 +249,7 @@ class Error < StandardError; end
# NOTE: This may not work on ruby > 1.9.

def self.detect_idle_timeout uri, max = 10
uri = URI uri unless URI::Generic === uri
uri = Bundler::URI uri unless Bundler::URI::Generic === uri
uri += '/'

req = Net::HTTP::Head.new uri.request_uri
Expand Down Expand Up @@ -513,13 +513,13 @@ def self.detect_idle_timeout uri, max = 10
# required currently, but highly recommended. Your library name should be
# good enough. This parameter will be required in a future version.
#
# +proxy+ may be set to a URI::HTTP or :ENV to pick up proxy options from
# +proxy+ may be set to a Bundler::URI::HTTP or :ENV to pick up proxy options from
# the environment. See proxy_from_env for details.
#
# In order to use a URI for the proxy you may need to do some extra work
# beyond URI parsing if the proxy requires a password:
# In order to use a Bundler::URI for the proxy you may need to do some extra work
# beyond Bundler::URI parsing if the proxy requires a password:
#
# proxy = URI 'http://proxy.example'
# proxy = Bundler::URI 'http://proxy.example'
# proxy.user = 'AzureDiamond'
# proxy.password = 'hunter2'
#
Expand Down Expand Up @@ -566,7 +566,7 @@ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
@verify_mode = nil
@cert_store = nil

@generation = 0 # incremented when proxy URI changes
@generation = 0 # incremented when proxy Bundler::URI changes

if HAVE_OPENSSL then
@verify_mode = OpenSSL::SSL::VERIFY_PEER
Expand Down Expand Up @@ -688,14 +688,14 @@ def error_message connection
end

##
# URI::escape wrapper
# Bundler::URI::escape wrapper

def escape str
CGI.escape str if str
end

##
# URI::unescape wrapper
# Bundler::URI::unescape wrapper

def unescape str
CGI.unescape str if str
Expand Down Expand Up @@ -803,12 +803,12 @@ def private_key= key
alias key= private_key=

##
# Sets the proxy server. The +proxy+ may be the URI of the proxy server,
# Sets the proxy server. The +proxy+ may be the Bundler::URI of the proxy server,
# the symbol +:ENV+ which will read the proxy from the environment or nil to
# disable use of a proxy. See #proxy_from_env for details on setting the
# proxy from the environment.
#
# If the proxy URI is set after requests have been made, the next request
# If the proxy Bundler::URI is set after requests have been made, the next request
# will shut-down and re-open all connections.
#
# The +no_proxy+ query parameter can be used to specify hosts which shouldn't
Expand All @@ -819,9 +819,9 @@ def private_key= key
def proxy= proxy
@proxy_uri = case proxy
when :ENV then proxy_from_env
when URI::HTTP then proxy
when Bundler::URI::HTTP then proxy
when nil then # ignore
else raise ArgumentError, 'proxy must be :ENV or a URI::HTTP'
else raise ArgumentError, 'proxy must be :ENV or a Bundler::URI::HTTP'
end

@no_proxy.clear
Expand All @@ -846,13 +846,13 @@ def proxy= proxy
end

##
# Creates a URI for an HTTP proxy server from ENV variables.
# Creates a Bundler::URI for an HTTP proxy server from ENV variables.
#
# If +HTTP_PROXY+ is set a proxy will be returned.
#
# If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the URI is given the
# If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the Bundler::URI is given the
# indicated user and password unless HTTP_PROXY contains either of these in
# the URI.
# the Bundler::URI.
#
# The +NO_PROXY+ ENV variable can be used to specify hosts which shouldn't
# be reached via proxy; if set it should be a comma separated list of
Expand All @@ -868,7 +868,7 @@ def proxy_from_env

return nil if env_proxy.nil? or env_proxy.empty?

uri = URI normalize_uri env_proxy
uri = Bundler::URI normalize_uri env_proxy

env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']

Expand Down Expand Up @@ -951,7 +951,7 @@ def request uri, req = nil, &block
retried = false
bad_response = false

uri = URI uri
uri = Bundler::URI uri
req = request_setup req || uri
response = nil

Expand Down Expand Up @@ -1024,13 +1024,13 @@ def request_failed exception, req, connection # :nodoc:
end

##
# Creates a GET request if +req_or_uri+ is a URI and adds headers to the
# Creates a GET request if +req_or_uri+ is a Bundler::URI and adds headers to the
# request.
#
# Returns the request.

def request_setup req_or_uri # :nodoc:
req = if URI === req_or_uri then
req = if Bundler::URI === req_or_uri then
Net::HTTP::Get.new req_or_uri.request_uri
else
req_or_uri
Expand Down
104 changes: 104 additions & 0 deletions lib/bundler/vendor/uri/lib/uri.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# frozen_string_literal: false
# Bundler::URI is a module providing classes to handle Uniform Resource Identifiers
# (RFC2396[http://tools.ietf.org/html/rfc2396]).
#
# == Features
#
# * Uniform way of handling URIs.
# * Flexibility to introduce custom Bundler::URI schemes.
# * Flexibility to have an alternate Bundler::URI::Parser (or just different patterns
# and regexp's).
#
# == Basic example
#
# require 'bundler/vendor/uri/lib/uri'
#
# uri = Bundler::URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
# #=> #<Bundler::URI::HTTP http://foo.com/posts?id=30&limit=5#time=1305298413>
#
# uri.scheme #=> "http"
# uri.host #=> "foo.com"
# uri.path #=> "/posts"
# uri.query #=> "id=30&limit=5"
# uri.fragment #=> "time=1305298413"
#
# uri.to_s #=> "http://foo.com/posts?id=30&limit=5#time=1305298413"
#
# == Adding custom URIs
#
# module Bundler::URI
# class RSYNC < Generic
# DEFAULT_PORT = 873
# end
# @@schemes['RSYNC'] = RSYNC
# end
# #=> Bundler::URI::RSYNC
#
# Bundler::URI.scheme_list
# #=> {"FILE"=>Bundler::URI::File, "FTP"=>Bundler::URI::FTP, "HTTP"=>Bundler::URI::HTTP,
# # "HTTPS"=>Bundler::URI::HTTPS, "LDAP"=>Bundler::URI::LDAP, "LDAPS"=>Bundler::URI::LDAPS,
# # "MAILTO"=>Bundler::URI::MailTo, "RSYNC"=>Bundler::URI::RSYNC}
#
# uri = Bundler::URI("rsync://rsync.foo.com")
# #=> #<Bundler::URI::RSYNC rsync://rsync.foo.com>
#
# == RFC References
#
# A good place to view an RFC spec is http://www.ietf.org/rfc.html.
#
# Here is a list of all related RFC's:
# - RFC822[http://tools.ietf.org/html/rfc822]
# - RFC1738[http://tools.ietf.org/html/rfc1738]
# - RFC2255[http://tools.ietf.org/html/rfc2255]
# - RFC2368[http://tools.ietf.org/html/rfc2368]
# - RFC2373[http://tools.ietf.org/html/rfc2373]
# - RFC2396[http://tools.ietf.org/html/rfc2396]
# - RFC2732[http://tools.ietf.org/html/rfc2732]
# - RFC3986[http://tools.ietf.org/html/rfc3986]
#
# == Class tree
#
# - Bundler::URI::Generic (in uri/generic.rb)
# - Bundler::URI::File - (in uri/file.rb)
# - Bundler::URI::FTP - (in uri/ftp.rb)
# - Bundler::URI::HTTP - (in uri/http.rb)
# - Bundler::URI::HTTPS - (in uri/https.rb)
# - Bundler::URI::LDAP - (in uri/ldap.rb)
# - Bundler::URI::LDAPS - (in uri/ldaps.rb)
# - Bundler::URI::MailTo - (in uri/mailto.rb)
# - Bundler::URI::Parser - (in uri/common.rb)
# - Bundler::URI::REGEXP - (in uri/common.rb)
# - Bundler::URI::REGEXP::PATTERN - (in uri/common.rb)
# - Bundler::URI::Util - (in uri/common.rb)
# - Bundler::URI::Escape - (in uri/common.rb)
# - Bundler::URI::Error - (in uri/common.rb)
# - Bundler::URI::InvalidURIError - (in uri/common.rb)
# - Bundler::URI::InvalidComponentError - (in uri/common.rb)
# - Bundler::URI::BadURIError - (in uri/common.rb)
#
# == Copyright Info
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# Documentation::
# Akira Yamada <akira@ruby-lang.org>
# Dmitry V. Sabanin <sdmitry@lrn.ru>
# Vincent Batts <vbatts@hashbangbash.com>
# License::
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
#

module Bundler::URI
end

require_relative 'uri/version'
require_relative 'uri/common'
require_relative 'uri/generic'
require_relative 'uri/file'
require_relative 'uri/ftp'
require_relative 'uri/http'
require_relative 'uri/https'
require_relative 'uri/ldap'
require_relative 'uri/ldaps'
require_relative 'uri/mailto'

0 comments on commit 8f80bda

Please sign in to comment.