forked from buggregator/laravel-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic functionality to show HTTP request info, should close bug…
- Loading branch information
Showing
21 changed files
with
480 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/Modules/HttpDump/Interfaces/Http/Controllers/StoreEventAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Modules\HttpDump\Interfaces\Http\Controllers; | ||
|
||
use App\Commands\FindProjectByName; | ||
use App\Commands\HandleReceivedEvent; | ||
use App\Contracts\Command\CommandBus; | ||
use App\Contracts\Query\QueryBus; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Arr; | ||
use Interfaces\Http\Controllers\Controller; | ||
use Spatie\RouteAttributes\Attributes\Any; | ||
use Spatie\RouteAttributes\Attributes\Where; | ||
use Symfony\Bridge\PsrHttpMessage\Factory\UploadedFile; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class StoreEventAction extends Controller | ||
{ | ||
#[Any(uri: 'httpdump/store/{extraData?}', name: 'httpdump.event.store')] | ||
#[Where('extraData', '(.*)')] | ||
public function __invoke( | ||
Request $request, | ||
CommandBus $commands, | ||
QueryBus $queryBus, | ||
ConsoleOutput $output, | ||
): void { | ||
$project = $queryBus->ask(new FindProjectByName('default')); | ||
$projectId = $project->getId(); | ||
|
||
$data = $this->prepareRequest($request); | ||
$commands->dispatch( | ||
new HandleReceivedEvent( | ||
(int) $projectId, | ||
'httpdump', | ||
$data, | ||
true | ||
) | ||
); | ||
} | ||
|
||
private function prepareRequest(Request $request) | ||
{ | ||
return [ | ||
'received_at' => now()->toDateTimeString(), | ||
'request' => [ | ||
'method' => $request->getMethod(), | ||
'uri' => $request->getRequestUri(), | ||
'headers' => $request->headers->all(), | ||
'body' => $request->getContent(), | ||
'query' => $request->query->all(), | ||
'post' => $this->getPostData($request), | ||
], | ||
]; | ||
} | ||
|
||
private function getPostData(Request $request): array | ||
{ | ||
$contentType = current(Arr::get($request->headers->all(), 'content-type', [])) ?: 'no content type'; | ||
|
||
if ($contentType === 'application/x-www-form-urlencoded') { | ||
return $request->request->all(); | ||
} | ||
|
||
if ($contentType === 'application/json') { | ||
return json_decode($request->getContent(), true); | ||
} | ||
|
||
if (str_starts_with($contentType, 'multipart/form-data') && $request->allFiles() !== []) { | ||
return array_map(function (UploadedFile $file) { | ||
return [ | ||
'originalName' => $file->getClientOriginalName(), | ||
'mime' => $file->getClientMimeType(), | ||
'size' => $file->getSize(), | ||
]; | ||
}, collect($request->files->all())->flatten()->toArray()); | ||
} | ||
|
||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Modules\HttpDump; | ||
|
||
use Modules\HttpDump\Contracts\EventHandler as EventHandlerContract; | ||
|
||
final class ServiceProvider extends \Illuminate\Support\ServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
$this->app->bind(EventHandlerContract::class, function () { | ||
return new EventHandler($this->app, []); | ||
}); | ||
} | ||
|
||
public function boot() | ||
{ | ||
$this->loadViewsFrom(__DIR__.'/resources/views', 'httpdump'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<!-- Используется на первой вкладке со всеми событиями --> | ||
<Event :event="event" class="event--httpdump"> | ||
<Link as="div" :href="event.route.show" class="link flex-grow"> | ||
<p>{{ event.event.request.method }} {{ event.event.request.uri }}</p> | ||
</Link> | ||
</Event> | ||
</template> | ||
|
||
<script> | ||
import Event from "../Event"; | ||
import {Link} from '@inertiajs/inertia-vue3' | ||
export default { | ||
components: { | ||
Link, Event | ||
}, | ||
props: { | ||
event: Object | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<div class="relative"> | ||
<Link as="div" :href="event.route.show" class="link flex-grow"> | ||
<p>{{ event.event.request.method }} {{ event.event.request.uri }}</p> | ||
<span class="text-xs"> {{ event.date }}</span> | ||
</Link> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import {Link} from '@inertiajs/inertia-vue3' | ||
export default { | ||
components: { Link }, | ||
props: { | ||
event: Object | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<template> | ||
<section class="py-5 px-4 md:px-6 lg:px-8 border-b"> | ||
<h1 class="mb-1 text-lg bold">Headers</h1> | ||
<Table> | ||
<TableRow :title="title" v-for="(value, title) in event.request.headers"> | ||
{{ value[0] || value}} | ||
</TableRow> | ||
</Table> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import Table from "@/Components/UI/Table"; | ||
import TableRow from "@/Components/UI/TableRow"; | ||
export default { | ||
components: { | ||
Table, TableRow | ||
}, | ||
props: { | ||
event: Object | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<template> | ||
<section class="py-5 px-4 md:px-6 lg:px-8 border-b"> | ||
<h1 class="mb-1 text-lg bold">POST Data</h1> | ||
<Table> | ||
<TableRow :title="title" v-for="(value, title) in event.request.post"> | ||
{{ value }} | ||
</TableRow> | ||
</Table> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import Table from "@/Components/UI/Table"; | ||
import TableRow from "@/Components/UI/TableRow"; | ||
export default { | ||
components: { | ||
Table, TableRow | ||
}, | ||
props: { | ||
event: Object | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<template> | ||
<section class="py-5 px-4 md:px-6 lg:px-8 border-b"> | ||
<h1 class="mb-1 text-lg bold">Query Parameters</h1> | ||
<Table> | ||
<TableRow :title="title" v-for="(value, title) in event.request.query"> | ||
{{ value }} | ||
</TableRow> | ||
</Table> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import Table from "@/Components/UI/Table"; | ||
import TableRow from "@/Components/UI/TableRow"; | ||
export default { | ||
components: { | ||
Table, TableRow | ||
}, | ||
props: { | ||
event: Object | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<section class="py-5 px-4 md:px-6 lg:px-8 border-b"> | ||
<h1 class="mb-1 text-lg bold">Request Body</h1> | ||
<p> | ||
<code> | ||
{{ event.request.body }} | ||
</code> | ||
</p> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
components: { | ||
}, | ||
props: { | ||
event: Object | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Event} from "@/Event" | ||
|
||
export default class extends Event{ | ||
labels = [] | ||
app = 'httpdump' | ||
|
||
constructor(event, id, timestamp) { | ||
super(event, id, timestamp) | ||
this.labels.push(this.event.request.method) | ||
} | ||
|
||
get type() { | ||
return 'httpdump' | ||
} | ||
} |
Oops, something went wrong.