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 end
begin begin
OpenURI.open_uri( headers = {
uri,
'Header' => 'application/vnd.github+json', 'Header' => 'application/vnd.github+json',
'X-GitHub-Api-Version' => '2022-11-28' 'X-GitHub-Api-Version' => '2022-11-28',
) do |f| }
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) response = JSON.parse(f.read)
# If the response is an array, it is likely to be a directory. In this # 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 } query = { :ref => rev }
uri.query = URI.encode_www_form query uri.query = URI.encode_www_form query
begin content = begin
OpenURI.open_uri( headers = { 'Content-Type' => 'application-json' }
uri, header['PRIVATE-TOKEN'] = ENV['GITLAB_API_PERSONAL_ACCESS_TOKEN'] if ENV['GITLAB_API_PERSONAL_ACCESS_TOKEN']
'Content-Type' => 'application/json',
'PRIVATE-TOKEN' => ENV['GITLAB_API_PERSONAL_ACCESS_TOKEN'], OpenURI.open_uri(uri, headers) do |f|
) do |f|
response = JSON.parse(f.read) response = JSON.parse(f.read)
if response['content'] && response['encoding'] == 'base64' if response['content'] && response['encoding'] == 'base64'