diff --git a/http-helper/Context/HttpHeaders.php b/http-helper/Context/HttpHeaders.php index 65f362c1..533802ed 100644 --- a/http-helper/Context/HttpHeaders.php +++ b/http-helper/Context/HttpHeaders.php @@ -19,6 +19,10 @@ trait HttpHeaders private array $_headers = []; + + private array $_server = []; + + /** * @param array $headers */ diff --git a/http-helper/Context/HttpParams.php b/http-helper/Context/HttpParams.php index 13ddd3e2..75e85453 100644 --- a/http-helper/Context/HttpParams.php +++ b/http-helper/Context/HttpParams.php @@ -36,6 +36,10 @@ trait HttpParams private ?array $_files = []; + /** @var string */ + private string $_body = ''; + + private mixed $_rawContent = ''; /** @@ -63,19 +67,29 @@ trait HttpParams } /** - * @param mixed|string $rawContent + * @param \Swoole\Http\Request $request */ - public function setRawContent(mixed $rawContent, string $context_type): void + public function setParseBody(\Swoole\Http\Request $request): void { - if (str_contains($context_type, 'json')) { - $this->_rawContent = json_decode($rawContent, true); - } else if (str_contains($context_type, 'xml')) { - $this->_rawContent = Xml::toArray($rawContent); + $content = $request->getContent(); + if (empty($content)) { + return; + } + $contentType = $request->header['content-type']; + if (str_contains($contentType, 'json')) { + $this->_posts = json_decode($contentType, true); + } else if (str_contains($contentType, 'xml')) { + $this->_posts = Xml::toArray($contentType); + } else if (str_contains($contentType, 'x-www-form-urlencoded')) { + $this->_posts = $request->post; + } else if (str_contains($contentType, 'serialize')) { + $this->_posts = unserialize($content); } else { - $this->_rawContent = $rawContent; + $this->_body = $content; } } + /** * @return mixed * @throws Exception diff --git a/http-server/Constrict/Request.php b/http-server/Constrict/Request.php index 1e76a609..e49ccd9a 100644 --- a/http-server/Constrict/Request.php +++ b/http-server/Constrict/Request.php @@ -57,17 +57,13 @@ class Request implements RequestInterface Context::setContext(Response::class, new Response()); $sRequest = new HttpResponse(); - - var_dump($request->getData(), $request->header); - $sRequest->setHeaders(array_merge($request->header, $request->server)); $sRequest->setUri($sRequest->getRequestUri()); $sRequest->setClientId($request->fd); - $sRequest->setRawContent($request->rawContent(), $sRequest->getContentType()); + $sRequest->setParseBody($request); $sRequest->setFiles($request->files ?? []); - $sRequest->setPosts($request->post ?? []); $sRequest->setGets($request->get ?? []); Context::setContext(HttpResponse::class, $sRequest);