Update OpenURI.open_uri handling of headers

This commit is contained in:
Gabriel Arazas 2023-03-06 23:43:08 +08:00
parent d846aaa159
commit 525e943370
2 changed files with 12 additions and 10 deletions

View File

@ -33,11 +33,14 @@ class GitHubRawIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
end
begin
OpenURI.open_uri(
uri,
headers = {
'Header' => 'application/vnd.github+json',
'X-GitHub-Api-Version' => '2022-11-28'
) do |f|
'X-GitHub-Api-Version' => '2022-11-28',
}
headers['Authorization'] = "Token #{ENV['GITHUB_API_BEARER_TOKEN']}" if ENV['GITHUB_API_BEARER_TOKEN']
OpenURI.open_uri(uri, headers) do |f|
response = JSON.parse(f.read)
# If the response is an array, it is likely to be a directory. In this

View File

@ -45,12 +45,11 @@ class GitLabRawIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
query = { :ref => rev }
uri.query = URI.encode_www_form query
begin
OpenURI.open_uri(
uri,
'Content-Type' => 'application/json',
'PRIVATE-TOKEN' => ENV['GITLAB_API_PERSONAL_ACCESS_TOKEN'],
) do |f|
content = begin
headers = { 'Content-Type' => 'application-json' }
header['PRIVATE-TOKEN'] = ENV['GITLAB_API_PERSONAL_ACCESS_TOKEN'] if ENV['GITLAB_API_PERSONAL_ACCESS_TOKEN']
OpenURI.open_uri(uri, headers) do |f|
response = JSON.parse(f.read)
if response['content'] && response['encoding'] == 'base64'