setMethod($method); $this->setData($contents); $this->setHeaders($this->encodeHeaders($headers)); $this->execute($path); if ($this->errCode !== 0) { throw new HttpClientException($this->errMsg, $this->errCode); } return new RawResponse( $this->statusCode, $this->decodeHeaders($this->headers ?? []), $this->body, $version ); } /** * @param string[] $headers * @return string[][] */ private function decodeHeaders(array $headers): array { $result = []; foreach ($headers as $name => $header) { // The key of header is lower case. $result[$name][] = $header; } if ($this->set_cookie_headers) { $result['set-cookie'] = $this->set_cookie_headers; } return $result; } /** * Swoole engine not support two-dimensional array. * @param string[][] $headers * @return string[] */ private function encodeHeaders(array $headers): array { $result = []; foreach ($headers as $name => $value) { $result[$name] = is_array($value) ? implode(',', $value) : $value; } return $result; } }