Skip to content

ServerRequest getQueryParams doesn't allow to unset all QueryParams using withQueryParams #202

Description

@HLeithner

Hi,

I have a middleware which parses the lang query parameter and set's the language in the container. Afterwards it removes the lang parameter from the query array and gives this new request to the next handler. This works aslong as you have at least another query parameter.

if you don't have a query parameter this psr-7 implementation automatically parses Uri directly.

    public function __invoke(Request $request, RequestHandler $handler): Response
    {
        $query = $request->getQueryParams();

        // do somthing with the $query['lang] entry

        // cleanup Parameters
        unset($query['lang']);
        $request = $request->withQueryParams($query);

        return $handler->handle($request);
    }

When I later validate the request for "unwanted" parameters with something like:

public function __invoke(Request $request, Response $response)
{
  $params = $request->getQueryParams();
  if (isset($params['lang'])) {
    // throw exception or what ever.
  }
}

The $params has the lang parameter set again because of this line
https://github.com/slimphp/Slim-Http/blob/master/src/ServerRequest.php#L220

Not sure why slim/http does it this way but I think it's wrong, because then Request::withQueryParams([]) is pretty useless and doesn't work.

Not sure if there is a workaround...

thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions