public function __construct(Request $req, array $options = [])
{
$this->req = $req;
$type = $req->getHeader("content-type");
$this->body = $req->getBody($this->totalSize = $this->size = $options["size"] ?? 131072);
$this->maxFieldLen = $options["field_len"] ?? 16384;
$this->maxInputVars = $options["input_vars"] ?? 200;
if ($type !== null && strncmp($type, "application/x-www-form-urlencoded", \strlen("application/x-www-form-urlencoded"))) {
if (!preg_match('#^\\s*multipart/(?:form-data|mixed)(?:\\s*;\\s*boundary\\s*=\\s*("?)([^"]*)\\1)?$#', $type, $m)) {
$this->req = null;
$this->parsing = true;
$this->result = new ParsedBody([]);
return;
}
$this->boundary = $m[2];
}
$this->body->when(function ($e, $data) {
$this->req = null;
\Amp\immediately(function () use($e, $data) {
if ($e) {
if ($e instanceof ClientSizeException) {
$e = new ClientException("", 0, $e);
}
$this->error = $e;
} else {
$this->result = $this->end($data);
}
if (!$this->parsing) {
$this->parsing = true;
foreach ($this->result->getNames() as $field) {
foreach ($this->result->getArray($field) as $_) {
foreach ($this->watchers as list($cb, $cbData)) {
$cb($field, $cbData);
}
}
}
}
$this->parsing = true;
foreach ($this->whens as list($cb, $cbData)) {
$cb($this->error, $this->result, $cbData);
}
$this->whens = $this->watchers = [];
});
});
}