Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Request::beforeSend callback. #164

Merged
merged 2 commits into from
Mar 8, 2015
Merged

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.

None yet

2 participants