Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor internal dashboard header handling #1459

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
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
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';
}
}
Loading