forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAphrontHTTPProxyResponse.php
65 lines (52 loc) · 1.51 KB
/
AphrontHTTPProxyResponse.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
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
<?php
/**
* Responds to a request by proxying an HTTP future.
*
* NOTE: This is currently very inefficient for large responses, and buffers
* the entire response into memory before returning it. It should be updated
* to stream the response instead, but we need to complete additional
* infrastructure work first.
*/
final class AphrontHTTPProxyResponse extends AphrontResponse {
private $future;
private $headers;
private $httpCode;
public function setHTTPFuture(HTTPSFuture $future) {
$this->future = $future;
return $this;
}
public function getHTTPFuture() {
return $this->future;
}
public function getCacheHeaders() {
return array();
}
public function getHeaders() {
$this->readRequestHeaders();
return array_merge(
parent::getHeaders(),
$this->headers,
array(
array('X-Phabricator-Proxy', 'true'),
));
}
public function buildResponseString() {
// TODO: AphrontResponse needs to support streaming responses.
return $this->readRequest();
}
public function getHTTPResponseCode() {
$this->readRequestHeaders();
return $this->httpCode;
}
private function readRequestHeaders() {
// TODO: This should read only the headers.
$this->readRequest();
}
private function readRequest() {
// TODO: This is grossly inefficient for large requests.
list($status, $body, $headers) = $this->future->resolve();
$this->httpCode = $status->getStatusCode();
$this->headers = $headers;
return $body;
}
}