-
Notifications
You must be signed in to change notification settings - Fork 80
/
HTTPClient.php
38 lines (33 loc) · 1.09 KB
/
HTTPClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace dokuwiki\plugin\oauth;
use dokuwiki\HTTP\DokuHTTPClient;
use OAuth\Common\Http\Client\ClientInterface;
use OAuth\Common\Http\Uri\UriInterface;
/**
* Implements the client interface using DokuWiki's HTTPClient
*/
class HTTPClient implements ClientInterface
{
/** @inheritDoc */
public function retrieveResponse(
UriInterface $endpoint,
$requestBody,
array $extraHeaders = [],
$method = 'POST'
) {
$http = new DokuHTTPClient();
$http->keep_alive = false;
$http->headers = array_merge($http->headers, $extraHeaders);
$ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method);
if (!$ok || $http->status < 200 || $http->status > 299) {
$msg = "An error occured during the request to the oauth provider:\n";
throw new HttpTokenResponseException(
$msg . $http->error . ' [HTTP ' . $http->status . ']',
$http->status,
$http->error,
$http->resp_body
);
}
return $http->resp_body;
}
}