private function processHeader(Stream $socket, string $method, $version)
    {
        $version = HttpVersion::castFrom($version);
        if (!$version->equals(HttpVersion::HTTP_1_0) && !$version->equals(HttpVersion::HTTP_1_1)) {
            throw new \InvalidArgumentException(
                    'Invalid HTTP version ' . $version . ', please use either '
                    . HttpVersion::HTTP_1_0 . ' or ' . HttpVersion::HTTP_1_1
            );
        }

        $path = $this->httpUri->path();
        if ($this->httpUri->hasQueryString() && $this->methodAllowsQueryString($method)) {
            $path .= '?' . $this->httpUri->queryString();
        }

        $socket->write(Http::line($method . ' ' . $path . ' ' . $version));
        $socket->write(Http::line('Host: ' . $this->httpUri->hostname()));
        foreach ($this->headers as $key => $value) {
            $socket->write(Http::line($key . ': ' . $value));
        }

        $socket->write(Http::emptyLine());
    }