Skip to content

Commit

Permalink
AppAPIProxy: send raw data and all headers to ExApp
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Jul 19, 2024
1 parent b75e303 commit 3eec399
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions lib/Controller/ExAppProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,24 @@ public function ExAppPost(string $appId, string $other): Response {

$options = [
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
'headers' => getallheaders(),
];
if (str_starts_with($this->request->getHeader('Content-Type'), 'multipart/form-data') || count($_FILES) > 0) {
$multipart = $this->buildMultipartFormData($this->prepareBodyParams($this->request->getParams()), $_FILES);
$options[RequestOptions::MULTIPART] = $multipart;
unset($options['headers']['Content-Type']);
unset($options['headers']['Content-Length']);
$options[RequestOptions::MULTIPART] = $this->buildMultipartFormData($_POST, $_FILES);
} else {
$options['body'] = $stream = fopen('php://input', 'r');
}
$bodyParams = $this->prepareBodyParams($this->request->getParams());

$response = $this->service->requestToExApp2(
$exApp, '/' . $other, $this->userId,
queryParams: $_GET, bodyParams: $bodyParams, options: $options,
request: $this->request,
queryParams: $_GET, options: $options, request: $this->request,
);

if (isset($stream) && is_resource($stream)) {
fclose($stream);
}
if (is_array($response)) {
return (new Response())->setStatus(500);
}
Expand All @@ -131,18 +137,24 @@ public function ExAppPut(string $appId, string $other): Response {

$options = [
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
'headers' => getallheaders(),
];
if (str_starts_with($this->request->getHeader('Content-Type'), 'multipart/form-data') || count($_FILES) > 0) {
$multipart = $this->buildMultipartFormData($this->prepareBodyParams($this->request->getParams()), $_FILES);
$options[RequestOptions::MULTIPART] = $multipart;
unset($options['headers']['Content-Type']);
unset($options['headers']['Content-Length']);
$options[RequestOptions::MULTIPART] = $this->buildMultipartFormData($_POST, $_FILES);
} else {
$options['body'] = $stream = fopen('php://input', 'r');
}
$bodyParams = $this->prepareBodyParams($this->request->getParams());

$response = $this->service->requestToExApp2(
$exApp, '/' . $other, $this->userId, 'PUT', queryParams: $_GET, bodyParams: $bodyParams,
options: $options,
request: $this->request,
$exApp, '/' . $other, $this->userId, 'PUT',
queryParams: $_GET, options: $options, request: $this->request,
);

if (isset($stream) && is_resource($stream)) {
fclose($stream);
}
if (is_array($response)) {
return (new Response())->setStatus(500);
}
Expand All @@ -157,14 +169,17 @@ public function ExAppDelete(string $appId, string $other): Response {
return new NotFoundResponse();
}

$bodyParams = $this->prepareBodyParams($this->request->getParams());
$stream = fopen('php://input', 'r');
$options = [
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
'body' => $stream,
'headers' => getallheaders(),
];
$response = $this->service->requestToExApp2(
$exApp, '/' . $other, $this->userId, 'DELETE', queryParams: $_GET, bodyParams: $bodyParams,
options: [
RequestOptions::COOKIES => $this->buildProxyCookiesJar($_COOKIE, $this->service->getExAppDomain($exApp)),
],
request: $this->request,
$exApp, '/' . $other, $this->userId, 'DELETE', queryParams: $_GET,
options: $options, request: $this->request,
);
fclose($stream);
if (is_array($response)) {
return (new Response())->setStatus(500);
}
Expand Down

0 comments on commit 3eec399

Please sign in to comment.