Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/base_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncio
from rnet import Impersonate, Client


async def main():
client = Client(
base_url="https://httpbin.org",
impersonate=Impersonate.Firefox135,
user_agent="rnet",
)
resp = await client.get("/stream/20")
print("Status Code: ", resp.status_code)
print("Version: ", resp.version)
print("Response URL: ", resp.url)
print("Headers: ", resp.headers.to_dict())
print("Content-Length: ", resp.content_length)
print("Encoding: ", resp.encoding)
print("Remote Address: ", resp.remote_addr)
streamer = resp.stream()
async for chunk in streamer:
print("Chunk: ", chunk)
await asyncio.sleep(0.1)


if __name__ == "__main__":
asyncio.run(main())
27 changes: 27 additions & 0 deletions rnet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ class Client:
def websocket(self, url:builtins.str, **kwds) -> typing.Any:
r"""
Sends a WebSocket request.

# Arguments

* `url` - The URL to send the WebSocket request to.
* `**kwds` - Additional WebSocket request parameters.

# Returns

A `WebSocket` object representing the WebSocket connection.

# Examples

```python
import rnet
import asyncio

async def main():
client = rnet.Client()
ws = await client.websocket("wss://echo.websocket.org")
await ws.send(rnet.Message.from_text("Hello, WebSocket!"))
message = await ws.recv()
print("Received:", message.data)
await ws.close()

asyncio.run(main())
```
"""
...

Expand Down Expand Up @@ -312,6 +338,7 @@ class ClientParams:
impersonate_os: typing.Optional[ImpersonateOS]
impersonate_skip_http2: typing.Optional[builtins.bool]
impersonate_skip_headers: typing.Optional[builtins.bool]
base_url: typing.Optional[builtins.str]
user_agent: typing.Optional[builtins.str]
headers_order: typing.Optional[builtins.list[builtins.str]]
referer: typing.Optional[builtins.bool]
Expand Down
Loading