public function addQueryData($key, $value) {
        // TODO: freeze the instance after configuration and automatically call copy()

        if (!is_string($key))       throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
        if (!isset($value))         $value = '';
        elseif (is_bool($value))    $value = (int) $value;
        elseif (!is_scalar($value)) throw new IllegalTypeException('Illegal type of parameter $value: '.gettype($value));

        $value = (string) $value;

        // TODO: extend to process multiple parameters at once
        $path      = $this->getPath();
        $separator = (strpos($path, '?')!==false) ? '&' : '?';
        $this->setPath($path.$separator.$key.'='.str_replace([' ','#','&'], ['%20','%23','%26'], $value));

        return $this;
    }