Skip to content

Is it possible to utilize Guzzle Http Request instead of your custom request? #635

@saas786

Description

@saas786

On my local server (wamp), my recurly requests takes more than few minutes to complete the request.
Spent few days tracing the issue, but cant put my finger on what the actual issue could be.

But changing:

$context = stream_context_create(['http' => $options]);

        $context = stream_context_create(['http' => $options]);
        $result = file_get_contents($url, false, $context);

to

        $guzzle = new \GuzzleHttp\Client();
        $request = new \GuzzleHttp\Psr7\Request($method, $url, $headers);
        $response = $guzzle
            ->send($request, ['body' => $body]);

        $result = $response->getBody()->getContents();

Make it snappier, and

$result contains the json data.

But $http_response_header causes the issue, as with:

        $http_response_header = [
            "HTTP/{$response->getProtocolVersion()} {$response->getStatusCode()} {$response->getReasonPhrase()}"
        ];
        foreach ($response->getHeaders() as $name => $values) {
            $http_response_header[] = $name . ': ' . implode(', ', $values) . "\r\n";
        }

It Emulates the headers, but only returns 7 headers, compared to original codes 18 headers.

Which ultimately fails the rest of the code after :

list($result, $response_header) = $this->http->execute($request->getMethod(), $request->getPath(), $request->getBodyAsJson(), $request->getHeaders());

Is there any fix I can use to make existing code work?

Or can you please utilize Guzzle http? Or make it pluggable?

###Update
It seems like everything is fine, was using $request instead of $response for getting headers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions