Browse files

Add BasicAuthListener

  • Loading branch information...
1 parent 2ba5da1 commit fb1d2a2ca827a222c176478c64cd7fca536e42b2 @rybakit committed Aug 17, 2012
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/Buzz/Listener/BasicAuthListener.php
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)
+ {
+ }
+}

0 comments on commit fb1d2a2

Please sign in to comment.