Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Http.php « Response « Request « Common « OpenCloud « lib « php-opencloud « 3rdparty « files_external « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7cb9e96346c4c584df39096ace004aace11b2b7 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php

namespace OpenCloud\Common\Request\Response;

use OpenCloud\Common\Base;

/**
 * The HttpResponse returns an object with status information, separated
 * headers, and any response body necessary.
 *
 * @api
 * @author Glen Campbell <glen.campbell@rackspace.com>
 */
 
class Http extends Base 
{

    private $errno;
    private $error;
    private $info = array();
    protected $body;
    protected $headers = array();

    /**
     * The constructor parses everything necessary
     */
    public function __construct($request, $data) 
    {
        // save the raw data (who knows? we might need it)
        $this->setBody($data);

        // and split each line into name: value pairs
        foreach($request->returnHeaders() as $line) {
            if (preg_match('/^([^:]+):\s+(.+?)\s*$/', $line, $matches)) {
                $this->headers[$matches[1]] = $matches[2];
            } else {
                $this->headers[$line] = trim($line);
            }
        }

        // @codeCoverageIgnoreStart
        if (isset($this->headers['Cache-Control'])) {
            $this->getLogger()->info('Cache-Control: {header}', array(
                'headers' => $this->headers['Cache-Control']
            ));
        }
        if (isset($this->headers['Expires'])) {
            $this->getLogger()->info('Expires: {header}', array(
                'headers' => $this->headers['Expires']
            ));
        }
        // @codeCoverageIgnoreEnd

        // set some other data
        $this->info = $request->info();
        $this->errno = $request->errno();
        $this->error = $request->error();
    }

    /**
     * Returns the full body of the request
     *
     * @return string
     */
    public function httpBody() 
    {
        return $this->body;
    }
    
    /**
     * Sets the body.
     * 
     * @param string $body
     */
    public function setBody($body)
    {
        $this->body = $body;
    }

    /**
     * Returns an array of headers
     *
     * @return associative array('header'=>value)
     */
    public function headers() 
    {
        return $this->headers;
    }

    /**
     * Returns a single header
     *
     * @return string with the value of the requested header, or NULL
     */
    public function header($name) 
    {
        return isset($this->headers[$name]) ? $this->headers[$name] : null;
    }

    /**
     * Returns an array of information
     *
     * @return array
     */
    public function info() 
    {
        return $this->info;
    }

    /**
     * Returns the most recent error number
     *
     * @return integer
     */
    public function errno()
    {
        return $this->errno;
    }

    /**
     * Returns the most recent error message
     *
     * @return string
     */
    public function error() 
    {
        return $this->error;
    }

    /**
     * Returns the HTTP status code
     *
     * @return integer
     */
    public function httpStatus() 
    {
        return $this->info['http_code'];
    }

}