Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add BasicAuthListener

  • Loading branch information...
commit fb1d2a2ca827a222c176478c64cd7fca536e42b2 1 parent 2ba5da1
@rybakit rybakit authored
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)
+ {
+ }
+}

3 comments on commit fb1d2a2

@brice

Hello,

How can we use this stuff?

@stof

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

@brice

Thanks

Please sign in to comment.
Something went wrong with that request. Please try again.