Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15505993
D11492.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11492.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -136,6 +136,7 @@
'AphrontFormView' => 'view/form/AphrontFormView.php',
'AphrontGlyphBarView' => 'view/widget/bars/AphrontGlyphBarView.php',
'AphrontHTMLResponse' => 'aphront/response/AphrontHTMLResponse.php',
+ 'AphrontHTTPProxyResponse' => 'aphront/response/AphrontHTTPProxyResponse.php',
'AphrontHTTPSink' => 'aphront/sink/AphrontHTTPSink.php',
'AphrontHTTPSinkTestCase' => 'aphront/sink/__tests__/AphrontHTTPSinkTestCase.php',
'AphrontIsolatedDatabaseConnectionTestCase' => 'infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php',
@@ -3248,6 +3249,7 @@
'AphrontFormView' => 'AphrontView',
'AphrontGlyphBarView' => 'AphrontBarView',
'AphrontHTMLResponse' => 'AphrontResponse',
+ 'AphrontHTTPProxyResponse' => 'AphrontResponse',
'AphrontHTTPSinkTestCase' => 'PhabricatorTestCase',
'AphrontIsolatedDatabaseConnectionTestCase' => 'PhabricatorTestCase',
'AphrontIsolatedHTTPSink' => 'AphrontHTTPSink',
diff --git a/src/aphront/response/AphrontHTTPProxyResponse.php b/src/aphront/response/AphrontHTTPProxyResponse.php
new file mode 100644
--- /dev/null
+++ b/src/aphront/response/AphrontHTTPProxyResponse.php
@@ -0,0 +1,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;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 16, 7:34 AM (1 w, 6 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7703853
Default Alt Text
D11492.diff (2 KB)
Attached To
Mode
D11492: Add an AphrontHTTPProxyResponse
Attached
Detach File
Event Timeline
Log In to Comment