Rayrun
← Back to Discord Forum

Routing same url with different handlers

danger.officialposted in #help-playwright
Open in Discord
danger.official
danger.official

Is there a way to route the same url using multiple handlers? I'm running the tasks concurrently and assigning a new route in each task. The request urls are the same but the body differs so I wanna separate em based on a local variable and return if the condition doesnt match without continue_ and let the other task edit the body and fulfill the request . Is there a way I can handle the routes based on their post data?

async def solve(page,session:aiohttp:ClientSession):
  async def rou(r):
    if "example.com" in r.request.url:
      data=r.request.post_data_json
      if not widgetid in data:
        return #let the other task handle the request
      #complete request using aiohttp session and then fulfill 
      await r.fulfill(headers=headers,json=body,status=resp.status)
      return
   await r.continue_() # if not example.com in r.request.url
  #assign widgetid, its different for every task
  #do stuff and finish the task
  return
async def main():
  #launch browser and create page
  #session is aiohttp.ClientSession()
  tasks=await asyncio.gather(solve(page,session),solve(page,session)) #the widget id differs the body of requests and is assigned in the tasks so I can't use a common route

This thread is trying to answer question "Is there a way to route the same url using multiple handlers based on their post data in Python?"

1 reply
danger.official
danger.official

Routing same url with different handlers

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.