From 837cf007060a750c19b267e6315d59163a08a880 Mon Sep 17 00:00:00 2001 From: Egor Vorobiev Date: Mon, 19 Aug 2019 21:08:44 +0300 Subject: [PATCH] fix: Add Auth header to individual batch requests * Fixes an issue where the authorization HTTP header wasn't being applied to individual batch requests. [pr #822, refs #817] --- lib/google/apis/core/batch.rb | 2 ++ spec/google/apis/core/service_spec.rb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/google/apis/core/batch.rb b/lib/google/apis/core/batch.rb index af60ce649..3e55183a4 100644 --- a/lib/google/apis/core/batch.rb +++ b/lib/google/apis/core/batch.rb @@ -177,6 +177,8 @@ module Google call.header.each do |key, value| request_head << sprintf("\r\n%s: %s", key, value) end + token = call.options.authorization + request_head << "\r\nAuthorization: Bearer #{token}" unless token.nil? request_head << sprintf("\r\nHost: %s", call.url.host) request_head << "\r\n\r\n" StringIO.new(request_head) diff --git a/spec/google/apis/core/service_spec.rb b/spec/google/apis/core/service_spec.rb index 39709f947..6d0746eae 100644 --- a/spec/google/apis/core/service_spec.rb +++ b/spec/google/apis/core/service_spec.rb @@ -277,13 +277,14 @@ EOF --outer Content-Type: application/http Content-Id: -Content-Length: 349 +Content-Length: 380 Content-Transfer-Encoding: binary POST /upload/zoo/animals? HTTP/1.1 X-Goog-Api-Client: #{x_goog_api_client_value} Content-Type: multipart/related; boundary=inner X-Goog-Upload-Protocol: multipart +Authorization: Bearer a token Host: www.googleapis.com --inner