Created
November 17, 2014 19:21
-
-
Save renier/538cbfe1e0fecc8c5e59 to your computer and use it in GitHub Desktop.
Make HTTParty pick out basic auth credentials from URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HTTParty | |
module ClassMethods | |
private | |
alias_method :orig_perform_request, :perform_request | |
def perform_request(http_method, path, options, &block) | |
if path.include? '@' | |
options ||= {} | |
scheme_auth, host_uri = path.split('@') | |
scheme, creds = scheme_auth.split('//') | |
path = "#{scheme}//#{host_uri}" | |
username, password = creds.split(':') | |
options[:basic_auth] = { username: username, password: password } | |
end | |
orig_perform_request(http_method, path, options, &block) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment