Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add BasicAuthListener #93

Merged
merged 2 commits into from

5 participants

@rybakit

No description provided.

@travisbot

This pull request passes (merged 4cee0eb into 2ba5da1).

@kriswallsmith kriswallsmith merged commit 988bf14 into from
@kriswallsmith

Thanks!

@stof stof referenced this pull request
Open

HTTP authentication #34

@brice

Hello,

How can we use this stuff?

$browser->addListener(new BasicAuthListener($username, $password))

Thanks

@rybakit rybakit deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 17, 2012
  1. @rybakit

    Add BasicAuthListener

    rybakit authored
  2. @rybakit
This page is out of date. Refresh to see the latest.
View
27 lib/Buzz/Listener/BasicAuthListener.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Buzz\Listener;
+
+use Buzz\Message\MessageInterface;
+use Buzz\Message\RequestInterface;
+
+class BasicAuthListener implements ListenerInterface
+{
+ private $username;
+ private $password;
+
+ public function __construct($username, $password)
+ {
+ $this->username = $username;
+ $this->password = $password;
+ }
+
+ public function preSend(RequestInterface $request)
+ {
+ $request->addHeader('Authorization: Basic '.base64_encode($this->username.':'.$this->password));
+ }
+
+ public function postSend(RequestInterface $request, MessageInterface $response)
+ {
+ }
+}
View
20 test/Buzz/Test/Listener/BasicAuthListenerTest.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Buzz\Test\Listener;
+
+use Buzz\Listener\BasicAuthListener;
+use Buzz\Message;
+
+class BasicAuthListenerTest extends \PHPUnit_Framework_TestCase
+{
+ public function testBasicAuthHeader()
+ {
+ $request = new Message\Request();
+ $this->assertEmpty($request->getHeader('Authorization'));
+
+ $listener = new BasicAuthListener('foo', 'bar');
+ $listener->preSend($request);
+
+ $this->assertEquals('Basic '.base64_encode('foo:bar'), $request->getHeader('Authorization'));
+ }
+}
Something went wrong with that request. Please try again.