public function to($target)
    {
        if (is_null($this->request)) {
            throw new \LogicException('Missing request instance.');
        }

        $target = new Uri($target);

        // Overwrite target scheme and host.
        $uri = $this->request->getUri()
            ->withScheme($target->getScheme())
            ->withHost($target->getHost());

        // Check for custom port.
        if ($port = $target->getPort()) {
            $uri = $uri->withPort($port);
        }

        // Check for subdirectory.
        if ($path = $target->getPath()) {
            $uri = $uri->withPath(rtrim($path, '/') . '/' . ltrim($uri->getPath(), '/'));
        }

        if (!empty($this->request->getQueryParams())) {
            // special case for rql
            $queryParams = $this->request->getQueryParams();

            if (count($queryParams) == 1 && empty(array_shift($queryParams))) {
                $queryKeys = array_keys($this->request->getQueryParams());
                $uri = $uri->withQuery($queryKeys[0]);
            } else {
                $uri = $uri->withQuery(http_build_query($this->request->getQueryParams()));
            }
        }

        $request = $this->request->withUri($uri);

        // make sure we don't send empty headers
        foreach ($request->getHeaders() as $headerName => $headerValue) {
            if (empty($headerValue[0])) {
                $request = $request->withoutHeader($headerName);
            }
        }

        return $this->client->send($request);
    }