<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

async def dispatch(self, app, payload):
        '''
        Dispatches an incoming request and passes it to the relevant resource
        returning the response.

        :param app:
            Application handler. must be passed as part of the request

        :param payload:
            The request payload, contains all the parameters of the request
        '''
        handler = None
        params = {}
        # parse request url, separating query params if any
        url = urlparse(payload['href'])
        path = url.path
        params.update(dict(parse_qsl(url.query)))
        params.update(payload.get('args', {}))
        # find the matching url , getting handler and arguments
        for route in self.urls(True, Resource.Protocol.websocket):
            match = re.match(route.path, path)
            if match:
                handler = route.handler
                params.update(match.groupdict())
                break
        if handler:
            request = Request(
                app=app,
                key=payload.get('key', None),
                method=payload.get('method', 'GET'),
                url=path,
                args=params,
                headers=payload.get('headers', None),
                body=payload.get('body', {})
            )
            response = await handler(request)
            return response
        return None