Skip to content

Commit 62a8fb2

Browse files
committed
fix: read AdapterMan request body globals
1 parent e0b6479 commit 62a8fb2

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

app/Http/Controllers/Internal/SubMeshRiskPolicyController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ public function update(Request $request, RiskPolicyService $policy)
2222

2323
$body = $request->getContent();
2424
if ($body === '') {
25-
// AdapterMan exposes the exact Workerman request body through RAW_BODY.
26-
$body = (string)($_SERVER['RAW_BODY'] ?? $request->server('RAW_BODY', ''));
25+
// AdapterMan exposes the exact Workerman request body through these globals.
26+
$body = (string)($GLOBALS['HTTP_RAW_REQUEST_DATA']
27+
?? $GLOBALS['HTTP_RAW_POST_DATA']
28+
?? $_SERVER['RAW_BODY']
29+
?? $request->server('RAW_BODY', ''));
2730
}
2831
if ($body === '' || strlen($body) > (int)config('submesh.risk_policy_max_bytes', 1048576)) {
2932
return response()->json(['message' => 'Invalid request.'], 400);

tests/Unit/SubMeshRiskPolicyControllerTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ public function testAcceptsAdapterManRawBodyFallback(): void
6666
$body = $this->body(false);
6767
$timestamp = (string)time();
6868
$signature = hash_hmac('sha256', $timestamp . "\n" . $body, str_repeat('a', 64));
69-
$previousBody = $_SERVER['RAW_BODY'] ?? null;
70-
$_SERVER['RAW_BODY'] = $body;
69+
$previousRequestBody = $GLOBALS['HTTP_RAW_REQUEST_DATA'] ?? null;
70+
$previousPostBody = $GLOBALS['HTTP_RAW_POST_DATA'] ?? null;
71+
$GLOBALS['HTTP_RAW_REQUEST_DATA'] = $body;
72+
$GLOBALS['HTTP_RAW_POST_DATA'] = $body;
7173
$request = Request::create('/api/internal/submesh/risk-policy', 'PUT', [], [], [], [
7274
'HTTP_X_SUBMESH_TIMESTAMP' => $timestamp,
7375
'HTTP_X_SUBMESH_SIGNATURE' => $signature,
@@ -77,10 +79,15 @@ public function testAcceptsAdapterManRawBodyFallback(): void
7779
try {
7880
$response = (new SubMeshRiskPolicyController())->update($request, new RiskPolicyService($this->path));
7981
} finally {
80-
if ($previousBody === null) {
81-
unset($_SERVER['RAW_BODY']);
82+
if ($previousRequestBody === null) {
83+
unset($GLOBALS['HTTP_RAW_REQUEST_DATA']);
8284
} else {
83-
$_SERVER['RAW_BODY'] = $previousBody;
85+
$GLOBALS['HTTP_RAW_REQUEST_DATA'] = $previousRequestBody;
86+
}
87+
if ($previousPostBody === null) {
88+
unset($GLOBALS['HTTP_RAW_POST_DATA']);
89+
} else {
90+
$GLOBALS['HTTP_RAW_POST_DATA'] = $previousPostBody;
8491
}
8592
}
8693

0 commit comments

Comments
 (0)