Skip to content

Commit

Permalink
Refactor post method in SoupPage class to include optional headers an…
Browse files Browse the repository at this point in the history
…d JSON data serialization
  • Loading branch information
mohamedmamdouh22 committed Jan 7, 2025
1 parent 43ac0a0 commit 5fdcc59
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sdk/harambe/contrib/soup/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,28 @@ async def post(
url,
headers=headers or self._extra_headers,
data=json.dumps(data),
**kwargs,
impersonate="chrome",
**kwargs,
)
if self._tracer:
self._tracer.log_request(res)

self._url = res.url
content_type = res.headers.get("Content-Type", "")

if "application/json" in content_type:
return res.json()

class SoupResponseWithStatus:
status: int = res.status_code
body: dict[str, Any] = res.json()

return SoupResponseWithStatus()

self._soup = BeautifulSoup(res.text, "html.parser")

class SoupResponseWithStatus:
status: int = res.status_code
body: str = res.text

return SoupResponseWithStatus()

Expand Down

0 comments on commit 5fdcc59

Please sign in to comment.