Skip to content

Commit

Permalink
Merge pull request #1459 from hydephp/realtime-compiler-code-cleanup
Browse files Browse the repository at this point in the history
Refactor internal dashboard header handling
  • Loading branch information
caendesilva authored Nov 13, 2023
2 parents 6230587 + 657a082 commit f849313
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/realtime-compiler/resources/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function registerAsyncForm(form, okHandler = null, errorHandler = null, beforeCa
method: "POST",
body: new FormData(event.target),
headers: new Headers({
"X-RC-Handler": "Async",
"Accept": "application/json",
}),
}).then(async response => {
if (response.ok) {
Expand Down
5 changes: 5 additions & 0 deletions packages/realtime-compiler/src/Http/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ protected function writeToConsole(string $message, string $context = 'dashboard'
$this->console->printMessage($message, $context);
}
}

protected function expectsJson(): bool
{
return array_change_key_case(getallheaders())['accept'] === 'application/json';
}
}
7 changes: 1 addition & 6 deletions packages/realtime-compiler/src/Http/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(?Request $request = null)
$this->loadFlashData();

if ($this->request->method === 'POST') {
$this->isAsync = $this->hasAsyncHeaders();
$this->isAsync = $this->expectsJson();
}
}

Expand Down Expand Up @@ -464,9 +464,4 @@ protected function findGeneralOpenBinary(): string
)
};
}

protected function hasAsyncHeaders(): bool
{
return (getallheaders()['X-RC-Handler'] ?? getallheaders()['x-rc-handler'] ?? null) === 'Async';
}
}

0 comments on commit f849313

Please sign in to comment.