def _copy_params(request, params=None):
    """
    Return a copy of the given request's params.

    If the request contains an empty 'q' param then it is omitted from the
    returned copy of the params, to avoid redirecting the browser to a URL with
    an empty trailing ?q=

    """
    if params is None:
        params = request.params.copy()

    if "q" in params and not params["q"].strip():
        del params["q"]

    return params