diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index 08587e1e1fd9..d1549aa4dfcb 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -341,6 +341,17 @@ public function withoutRedirecting() }); } + /** + * Specify the user agent for the request. + * + * @param string $userAgent + * @return $this + */ + public function withUserAgent($userAgent) + { + return $this->withHeaders(['User-Agent' => $userAgent]); + } + /** * Indicate that TLS certificates should not be verified. * diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 6a599b2fdb6d..39cf36aadfd6 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -237,6 +237,18 @@ public function testItCanSendToken() }); } + public function testItCanSendUserAgent() + { + $this->factory->fake(); + + $this->factory->withUserAgent('Laravel')->post('http://foo.com/json'); + + $this->factory->assertSent(function (Request $request) { + return $request->url() === 'http://foo.com/json' && + $request->hasHeader('User-Agent', 'Laravel'); + }); + } + public function testSequenceBuilder() { $this->factory->fake([