Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/thor/actions/file_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ def link_file(source, *args)
# ==== Parameters
# source<String>:: the address of the given content.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
# config<Hash>:: give :verbose => false to not log the status, and
# :http_headers => <Hash> to add headers to an http request.
#
# ==== Examples
#
# get "http://gist.github.com/103208", "doc/README"
#
# get "http://gist.github.com/103208", "doc/README", :http_headers => {"Content-Type" => "application/json"}
#
# get "http://gist.github.com/103208" do |content|
# content.split("\n").first
# end
Expand All @@ -82,7 +85,7 @@ def get(source, *args, &block)

render = if source =~ %r{^https?\://}
require "open-uri"
URI.send(:open, source) { |input| input.binmode.read }
URI.send(:open, source, config.fetch(:http_headers, {})) { |input| input.binmode.read }
else
source = File.expand_path(find_in_source_paths(source.to_s))
open(source) { |input| input.binmode.read }
Expand Down
10 changes: 10 additions & 0 deletions spec/actions/file_manipulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ def file
expect(content).to eq(body)
end
end

it "accepts http headers" do
body = "__start__\nHTTPFILE\n__end__\n"
headers = {"Content-Type" => "application/json"}
stub_request(:get, "https://example.com/file.txt").with(:headers => headers).to_return(:body => body.dup)
action :get, "https://example.com/file.txt", {:http_headers => headers} do |content|
expect(a_request(:get, "https://example.com/file.txt")).to have_been_made
expect(content).to eq(body)
end
end
end

describe "#template" do
Expand Down