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', @@ -3240,6 +3241,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 @@ +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; + } + +}