Skip to content

Instantly share code, notes, and snippets.

@geoffyoungs
Created March 25, 2021 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffyoungs/8c5f2d01d0f9009405dbce0e0723816e to your computer and use it in GitHub Desktop.
Save geoffyoungs/8c5f2d01d0f9009405dbce0e0723816e to your computer and use it in GitHub Desktop.
convert ruby Net::HTTP::Get to curl command line
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