diff --git a/features/checkout.feature b/features/checkout.feature index e1e11aad..3f24fc8e 100644 --- a/features/checkout.feature +++ b/features/checkout.feature @@ -11,6 +11,7 @@ Feature: hub checkout Given the GitHub API server: """ get('/repos/mojombo/jekyll/pulls/77') { + halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json' json :head => { :label => 'mislav:fixes', :repo => { :private => false } diff --git a/features/fork.feature b/features/fork.feature index bc90d94e..3d3c70cf 100644 --- a/features/fork.feature +++ b/features/fork.feature @@ -42,6 +42,7 @@ Feature: hub fork Given the GitHub API server: """ get('/repos/mislav/dotfiles') { + halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json' json :parent => { :html_url => 'https://github.com/unrelated/dotfiles' } } """ diff --git a/lib/hub/github_api.rb b/lib/hub/github_api.rb index fb362ece..744426b4 100644 --- a/lib/hub/github_api.rb +++ b/lib/hub/github_api.rb @@ -123,7 +123,7 @@ module Hub res.error! unless res.success? raw_url = res.data['files'].values.first['raw_url'] res = get(raw_url) do |req| - req['Accept'] = '*/*' + req['Accept'] = 'text/plain' end res.error! unless res.success? res.body @@ -228,6 +228,7 @@ module Hub req['User-Agent'] = "Hub #{Hub::VERSION}" apply_authentication(req, url) yield req if block_given? + finalize_request(req, url) begin res = http.start { http.request(req) } @@ -261,6 +262,12 @@ module Hub req.basic_auth user, pass end + def finalize_request(req, url) + if !req['Accept'] || req['Accept'] == '*/*' + req['Accept'] = 'application/vnd.github.v3+json' + end + end + def create_connection url use_ssl = 'https' == url.scheme diff --git a/test/hub_test.rb b/test/hub_test.rb index 2475a3f2..8e6aec63 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -190,7 +190,7 @@ class HubTest < Minitest::Test })) stub_request(:get, "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"). - with(:headers => {'Accept'=>'*/*'}). + with(:headers => {'Accept'=>'text/plain'}). to_return(:status => 200) with_tmpdir('/tmp/') do