Created
March 25, 2021 15:54
-
-
Save geoffyoungs/8c5f2d01d0f9009405dbce0e0723816e to your computer and use it in GitHub Desktop.
convert ruby Net::HTTP::Get to curl command line
This file contains 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
require 'shellwords' | |
def curl_command(uri, http_get) | |
curl = ['curl', '--http1.1'] | |
http_get.each_capitalized do |h,v| | |
case h | |
when 'User-Agent' | |
curl << '--user-agent' << v | |
else | |
curl << '-H' << "#{h}: #{v}" | |
end | |
end | |
curl << uri.to_s | |
Shellwords.shelljoin(curl) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment