Skip to content

Commit

Permalink
Add BasicAuthListener
Browse files Browse the repository at this point in the history
  • Loading branch information
rybakit committed Aug 17, 2012
1 parent 2ba5da1 commit fb1d2a2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Buzz/Listener/BasicAuthListener.php
Original file line number Diff line number Diff line change
@@ -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)
{
}
}

3 comments on commit fb1d2a2

@brice
Copy link

@brice brice commented on fb1d2a2 Jan 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

How can we use this stuff?

@stof
Copy link
Contributor

@stof stof commented on fb1d2a2 Jan 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@brice
Copy link

@brice brice commented on fb1d2a2 Jan 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Please sign in to comment.