blob: 9358eba151bffb056720840f31e40e47b9d017e2 (
plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
/**
* Nextcloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sean Molenaar <smillernl@me.com>
* @copyright 2018 Sean Molenaar
*/
namespace OCA\News\Config;
use FeedIo\Adapter\ResponseInterface;
use GuzzleHttp\Message\ResponseInterface as GuzzleResponseInterface;
/**
* Guzzle dependent HTTP Response
*/
class LegacyGuzzleResponse implements ResponseInterface
{
const HTTP_LAST_MODIFIED = 'Last-Modified';
/**
* @var \GuzzleHttp\Message\ResponseInterface
*/
protected $response;
/**
* @param \GuzzleHttp\Message\ResponseInterface
*/
public function __construct(GuzzleResponseInterface $psrResponse)
{
$this->response = $psrResponse;
}
/**
* @return boolean
*/
public function isModified()
{
return $this->response->getStatusCode() !== 304 && $this->response->getBody()->getSize() > 0;
}
/**
* @return \Psr\Http\Message\StreamInterface
*/
public function getBody()
{
return $this->response->getBody();
}
/**
* @return \DateTime|null
*/
public function getLastModified()
{
if ($this->response->hasHeader(static::HTTP_LAST_MODIFIED)) {
$lastModified = \DateTime::createFromFormat(
\DateTime::RFC2822,
$this->getHeader(static::HTTP_LAST_MODIFIED)
);
return false === $lastModified ? null : $lastModified;
}
return;
}
/**
* @return array
*/
public function getHeaders()
{
return $this->response->getHeaders();
}
/**
* @param string $name
* @return string[]
*/
public function getHeader($name)
{
return current($this->response->getHeader($name));
}
}
|