镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/Controller/ExAppProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
parent::__construct(Application::APP_ID, $request);
}

private function createProxyResponse(string $path, IResponse $response, $cache = true): ProxyResponse {
private function createProxyResponse(string $path, IResponse $response, bool $isHTML, $cache = true): ProxyResponse {
$headersToIgnore = ['aa-version', 'ex-app-id', 'authorization-app-api', 'ex-app-version', 'aa-request-id'];
$responseHeaders = [];
foreach ($response->getHeaders() as $key => $value) {
Expand All @@ -58,7 +58,6 @@ private function createProxyResponse(string $path, IResponse $response, $cache =
}
$content = $response->getBody();

$isHTML = pathinfo($path, PATHINFO_EXTENSION) === 'html';
if ($isHTML) {
$nonce = $this->nonceManager->getNonce();
$content = str_replace(
Expand Down Expand Up @@ -98,9 +97,11 @@ public function ExAppGet(string $appId, string $other): Response {
if ($exApp === null) {
return new NotFoundResponse();
}
$isHTML = pathinfo($other, PATHINFO_EXTENSION) === 'html';

$response = $this->service->requestToExApp2(
$exApp, '/' . $other, $this->userId, 'GET', queryParams: $_GET, options: [
'stream' => !$isHTML, // Can't stream HTML
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
RequestOptions::HEADERS => $this->buildHeadersWithExclude($route, getallheaders()),
RequestOptions::TIMEOUT => 0,
Expand All @@ -112,7 +113,7 @@ public function ExAppGet(string $appId, string $other): Response {
}

$this->processBruteforce($bruteforceProtection, $delay, $response->getStatusCode());
return $this->createProxyResponse($other, $response);
return $this->createProxyResponse($other, $response, $isHTML);
}

#[PublicPage]
Expand All @@ -126,8 +127,10 @@ public function ExAppPost(string $appId, string $other): Response {
if ($exApp === null) {
return new NotFoundResponse();
}
$isHTML = pathinfo($other, PATHINFO_EXTENSION) === 'html';

$options = [
'stream' => !$isHTML,
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
RequestOptions::HEADERS => $this->buildHeadersWithExclude($route, getallheaders()),
RequestOptions::TIMEOUT => 0,
Expand All @@ -153,7 +156,7 @@ public function ExAppPost(string $appId, string $other): Response {
}

$this->processBruteforce($bruteforceProtection, $delay, $response->getStatusCode());
return $this->createProxyResponse($other, $response);
return $this->createProxyResponse($other, $response, $isHTML);
}

#[PublicPage]
Expand All @@ -167,9 +170,11 @@ public function ExAppPut(string $appId, string $other): Response {
if ($exApp === null) {
return new NotFoundResponse();
}
$isHTML = pathinfo($other, PATHINFO_EXTENSION) === 'html';

$stream = fopen('php://input', 'r');
$options = [
'stream' => !$isHTML,
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
RequestOptions::BODY => $stream,
RequestOptions::HEADERS => $this->buildHeadersWithExclude($route, getallheaders()),
Expand All @@ -185,7 +190,7 @@ public function ExAppPut(string $appId, string $other): Response {
}

$this->processBruteforce($bruteforceProtection, $delay, $response->getStatusCode());
return $this->createProxyResponse($other, $response);
return $this->createProxyResponse($other, $response, $isHTML);
}

#[PublicPage]
Expand All @@ -199,9 +204,11 @@ public function ExAppDelete(string $appId, string $other): Response {
if ($exApp === null) {
return new NotFoundResponse();
}
$isHTML = pathinfo($other, PATHINFO_EXTENSION) === 'html';

$stream = fopen('php://input', 'r');
$options = [
'stream' => !$isHTML,
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
RequestOptions::BODY => $stream,
RequestOptions::HEADERS => $this->buildHeadersWithExclude($route, getallheaders()),
Expand All @@ -217,7 +224,7 @@ public function ExAppDelete(string $appId, string $other): Response {
}

$this->processBruteforce($bruteforceProtection, $delay, $response->getStatusCode());
return $this->createProxyResponse($other, $response);
return $this->createProxyResponse($other, $response, $isHTML);
}

private function prepareProxy(
Expand Down