Skip to content

Commit f708454

Browse files
committed
fix(query): Fix request query missing
1 parent 5f7b2ed commit f708454

File tree

9 files changed

+3397
-3017
lines changed

9 files changed

+3397
-3017
lines changed

Diff for: Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ update:
7474
build:
7575
docker-compose build
7676

77-
run: xdebug-init
78-
${DOCKER_COMPOSE_RUN} app bash -c "/var/www/html/whp --channel-uuid=$(channel) --forward-url=$(url)"
77+
build.whp:
78+
${DOCKER_COMPOSE_EXEC_WWW} app bash -c "./whp app:build"
79+
docker compose build whp
80+
81+
run: up
82+
up:
83+
docker compose up -d
7984

8085
xdebug-init:
8186
@if [ $$USER = 'vagrant' ]; then \
@@ -104,3 +109,6 @@ chl-first:
104109
${CONV_CHL_DR} \
105110
-c "${CONV_CHL_CMD} --first-release"
106111

112+
113+
ssh:
114+
${DOCKER_COMPOSE_EXEC_WWW} app bash

Diff for: src/app/Commands/Concerns/ForwardsProxyWebhooks.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function onMessage(string $forwardUrl): callable
3737
$timestamp = Carbon::now()->setTimezone($tz)->toDateTimeString();
3838
render("<h2 class='font-bold italic text-center text-lime-500'>Webhook received: {$timestamp} ({$tz})</h2>");
3939

40-
$requestData = RequestData::fromRaw($data->request);
40+
$requestData = RequestData::fromRaw((array) $data->request);
4141
$start = microtime(true);
4242
$response = RequestForwarder::make($data->request)->forward($forwardUrl);
4343
$forwardedInSeconds = round(microtime(true) - $start, 3) . 's';

Diff for: src/app/Commands/ProxyCommand.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use InvalidArgumentException;
1616
use React\EventLoop\LoopInterface;
1717
use Throwable;
18+
use function Laravel\Prompts\text;
1819

1920
class ProxyCommand extends Command
2021
{
@@ -39,13 +40,10 @@ protected function getLoop(): LoopInterface
3940

4041
public function handle(): void
4142
{
42-
$channelIdentifier = $this->option('channel') ?? $this->ask('Enter the channel UUID or webhook URL:');
43-
44-
if (empty($channelIdentifier)) {
45-
$this->error('The channel identifier is required');
46-
47-
return;
48-
}
43+
$channelIdentifier = $this->option('channel') ?? text(
44+
'Enter the channel UUID or webhook URL:',
45+
required: true,
46+
);
4947

5048
try {
5149
$channelUuid = $this->webhookProxy->parseChannelUuid($channelIdentifier);
@@ -55,7 +53,7 @@ public function handle(): void
5553
return;
5654
}
5755

58-
$forwardUrl = $this->option('forward-url') ?? $this->ask('Enter the URL to forward to:');
56+
$forwardUrl = $this->option('forward-url') ?? text('Enter the URL to forward to:');
5957

6058
if (empty($forwardUrl)) {
6159
$this->error('The forward URL is required');

Diff for: src/app/Proxy/RequestData.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,40 @@
55
namespace App\Proxy;
66

77
use GuzzleHttp\Psr7\Request;
8-
use stdClass;
98

109
class RequestData
1110
{
11+
public readonly array $query;
12+
1213
public readonly array $headers;
1314

15+
1416
public function __construct(
1517
public readonly string $method,
1618
protected array|object|string $body,
17-
array|stdClass $headers,
19+
array|object $query = [],
20+
array|object $headers = [],
1821
) {
1922
$this->headers = static::normalizeHeaders($headers);
23+
$this->query = (array) $query;
2024
}
2125

22-
public static function fromRaw(array|stdClass $request): static
26+
public static function fromRaw(array $request): static
2327
{
24-
$request = (array) $request;
25-
2628
return new static(
2729
$request['method'],
2830
$request['body'],
31+
$request['query'],
2932
$request['headers'],
3033
);
3134
}
3235

33-
protected static function normalizeHeaders(array|stdClass $headers): array
36+
protected static function normalizeHeaders(array|object $headers): array
3437
{
35-
$headers = (array) $headers;
36-
37-
return array_map(fn($header) => is_array($header) ? $header[0] : $header, $headers);
38+
return array_map(
39+
fn($header) => is_array($header) ? $header[0] : $header,
40+
(array) $headers,
41+
);
3842
}
3943

4044
public function body(): string

Diff for: src/app/Proxy/RequestForwarder.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ class RequestForwarder
1616
{
1717
protected RequestData $payload;
1818

19+
protected Client $httpClient;
20+
1921
public function __construct(object $request)
2022
{
21-
$contentType = $request->headers->{'content-type'}[0] ?? 'application/json';
23+
$contentType = $request->headers->{'content-type'}[0] ?? 'application/json';
2224

2325
$body = str_contains($contentType, 'text') && isset($request->body->raw)
2426
? $request->body->raw
@@ -27,8 +29,13 @@ public function __construct(object $request)
2729
$this->payload = new RequestData(
2830
$request->method,
2931
$body,
30-
(array) $request->headers
32+
(array) $request->query,
33+
(array) $request->headers,
3134
);
35+
36+
$this->httpClient = new Client([
37+
'verify' => false,
38+
]);
3239
}
3340

3441
public static function make(object $request): static
@@ -38,10 +45,10 @@ public static function make(object $request): static
3845

3946
public function forward(string $url): ResponseInterface
4047
{
41-
$client = new Client();
42-
4348
try {
44-
return $client->send($this->payload->toRequest($url));
49+
return $this->httpClient->send($this->payload->toRequest($url), [
50+
'query' => $this->payload->query,
51+
]);
4552
} catch (RequestException|ProviderException|BadResponseException $e) {
4653
return $e->getResponse() ?? new Response(status: 500, body: $e->getMessage());
4754
} catch (GuzzleException $e) {

Diff for: src/builds/whp

3.79 MB
Binary file not shown.

Diff for: src/composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
"php": "^8.1",
88
"guzzlehttp/guzzle": "^7.7",
99
"guzzlehttp/psr7": "^2.5",
10-
"nunomaduro/termwind": "^1.15.1",
1110
"ratchet/rfc6455": "^0.3.1",
1211
"react/socket": "^1.12"
1312
},
1413
"require-dev": {
15-
"laravel-zero/framework": "^10.0.2",
14+
"laravel-zero/framework": "^11.0",
1615
"laravel/pint": "^1.8",
1716
"mockery/mockery": "^1.5.1",
1817
"pestphp/pest": "^2.5"

0 commit comments

Comments
 (0)