This commit is contained in:
2021-08-27 11:39:11 +08:00
parent 6bb25e0ffd
commit 0fcf75f468
3 changed files with 26 additions and 12 deletions
+4
View File
@@ -19,6 +19,10 @@ trait HttpHeaders
private array $_headers = [];
private array $_server = [];
/**
* @param array $headers
*/
+21 -7
View File
@@ -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
+1 -5
View File
@@ -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);