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

Add support for return Headers from response #79

Merged
merged 1 commit into from
Dec 8, 2017

Conversation

bbiao
Copy link
Contributor

@bbiao bbiao commented Dec 7, 2017

Useage

$res = Curl::to('http://www.example.com')->returnResponseHeader()->returnResponseObject()->get();

$res = [
...
'header' => [ h1 => v1, h2 => v2 ]
...
]

Useage

$res = Curl::to('http://www.example.com')->returnResponseHeader()->returnResponseObject()->get();

$res = [
    ...
    'header' => [ h1 => v1, h2 => v2 ]
    ...
]
@elimentz
Copy link
Contributor

elimentz commented Dec 7, 2017

Interesting addition, I like it! Can you provide me a clear example of the usage? I mean, an actual URL I can try with the headers you want to see? I would like to test this myself before I put it in

@bbiao
Copy link
Contributor Author

bbiao commented Dec 8, 2017

Hi, @elimentz

This is the example:

public function curl() {
     $res = Curl::to('https://www.baidu.com')->returnResponseHeader()->returnResponseObject()->get();
     dd($res->header);
 }

and it will output:

array:13 [▼
"Accept-Ranges" => "bytes"
"Cache-Control" => "no-cache"
"Connection" => "Keep-Alive"
"Content-Length" => "14720"
"Content-Type" => "text/html"
"Date" => "Fri, 08 Dec 2017 02:02:47 GMT"
"Last-Modified" => "Fri, 01 Dec 2017 02:29:00 GMT"
"P3p" => "CP=" OTI DSP COR IVA OUR IND COM ""
"Pragma" => "no-cache"
"Server" => "BWS/1.1"
"Set-Cookie" => "PSTM=1512698567; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com"
"Vary" => "Accept-Encoding"
"X-Ua-Compatible" => "IE=Edge,chrome=1"
]

@elimentz elimentz merged commit c69c540 into ixudra:master Dec 8, 2017
@elimentz
Copy link
Contributor

elimentz commented Dec 8, 2017

Thanks for contributing!!

@elimentz
Copy link
Contributor

elimentz commented Dec 8, 2017

Now available in v6.16.0. Be aware: syntax is slightly different than how you submitted it:

    use Ixudra\Curl\Facades\Curl;

    // Send a GET request to http://www.foo.com/bar and return a response object with additional information including response headers
    $response = Curl::to('http://www.foo.com/bar')
        ->withResponseHeaders()
        ->returnResponseObject()
        ->get();
            
    $content = $response->content;
    $headers = $response->headers;

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