File tree Expand file tree Collapse file tree 2 files changed +59
-6
lines changed Expand file tree Collapse file tree 2 files changed +59
-6
lines changed Original file line number Diff line number Diff line change @@ -804,12 +804,24 @@ public function prepareScopes()
804804 */
805805 public function execute (RequestInterface $ request , $ expectedClass = null )
806806 {
807- $ request = $ request ->withHeader (
808- 'User-Agent ' ,
809- $ this ->config ['application_name ' ]
810- . " " . self ::USER_AGENT_SUFFIX
811- . $ this ->getLibraryVersion ()
812- );
807+ $ request = $ request
808+ ->withHeader (
809+ 'User-Agent ' ,
810+ sprintf (
811+ '%s %s%s ' ,
812+ $ this ->config ['application_name ' ],
813+ self ::USER_AGENT_SUFFIX ,
814+ $ this ->getLibraryVersion ()
815+ )
816+ )
817+ ->withHeader (
818+ 'x-goog-api-client ' ,
819+ sprintf (
820+ 'gl-php/%s gdcl/%s ' ,
821+ phpversion (),
822+ $ this ->getLibraryVersion ()
823+ )
824+ );
813825
814826 if ($ this ->config ['api_format_v2 ' ]) {
815827 $ request = $ request ->withHeader (
Original file line number Diff line number Diff line change @@ -707,4 +707,45 @@ public function testExecuteWithFormat()
707707 $ request = new Request ('POST ' , 'http://foo.bar/ ' );
708708 $ client ->execute ($ request );
709709 }
710+
711+ public function testExecuteSetsCorrectHeaders ()
712+ {
713+ $ this ->onlyGuzzle6 ();
714+
715+ $ client = new Google_Client ();
716+ $ guzzle = $ this ->getMock ('GuzzleHttp\Client ' );
717+ $ guzzle ->expects ($ this ->once ())
718+ ->method ('send ' )
719+ ->with (
720+ $ this ->callback (
721+ function (RequestInterface $ request ) {
722+ $ userAgent = sprintf (
723+ '%s%s ' ,
724+ Google_Client::USER_AGENT_SUFFIX ,
725+ Google_Client::LIBVER
726+ );
727+ $ xGoogApiClient = sprintf (
728+ 'gl-php/%s gdcl/%s ' ,
729+ phpversion (),
730+ Google_Client::LIBVER
731+ );
732+
733+ if ($ request ->getHeaderLine ('User-Agent ' ) !== $ userAgent ) {
734+ return false ;
735+ }
736+
737+ if ($ request ->getHeaderLine ('x-goog-api-client ' ) !== $ xGoogApiClient ) {
738+ return false ;
739+ }
740+
741+ return true ;
742+ }
743+ )
744+ )->will ($ this ->returnValue (new Response (200 , [], null )));
745+
746+ $ client ->setHttpClient ($ guzzle );
747+
748+ $ request = new Request ('POST ' , 'http://foo.bar/ ' );
749+ $ client ->execute ($ request );
750+ }
710751}
You can’t perform that action at this time.
0 commit comments