Skip to content

Conversation

@LeviticusMB
Copy link

Useful for computing custom headers or resolving relative URLs.

Here's an example how how it can be used to support relative URLs and adding a Hawk Authentication header:

Request::ini(Request::init()
             ->followRedirects(true)
             ->sendsAndExpects('application/json')
             ->withAccept('application/json')
             ->beforeSend(function($req) use ($onslip360_url, $onslip360_key) {
                     // Resolve relative URLs
                     $req->uri($onslip360_url->resolve($req->uri)->getURL());

                     // Add Authentication header
                     $hawk = \Dflydev\Hawk\Client\ClientBuilder::create()
                         ->build()
                         ->createRequest($onslip360_key, $req->uri, $req->method,
                                         !isset($req->serialized_payload) ? array() : array('payload'      => $req->serialized_payload,
                                                                                            'content_type' => $req->content_type));
                     $req->addHeader($hawk->header()->fieldName(), $hawk->header()->fieldValue());
                 }));

Useful for computing custom headers or resolving relative URLs.
@nategood
Copy link
Owner

Nice. I like it. Ideally I'd like to see some simple test coverage added.

@LeviticusMB
Copy link
Author

Added one.

nategood pushed a commit that referenced this pull request Mar 8, 2015
Added Request::beforeSend callback.
@nategood nategood merged commit e5822e5 into nategood:master Mar 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants