ProxyContext
Proxy options used to configure the proxy handler.
This class manages the context for proxy operations, including the target URL, session management, and request/response handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
URL
|
The target URL to proxy requests to. |
required |
session_factory
|
SessionFactory | None
|
Optional factory function to create client sessions. If not provided, defaults to aiohttp.ClientSession. |
None
|
state
|
dict | None
|
Optional state object to store additional context data. |
None
|
Source code in aiorp/context.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
request
property
Get the current proxy request.
Returns:
| Type | Description |
|---|---|
ProxyRequest
|
The current ProxyRequest object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the request has not been set yet. |
response
property
Get the current proxy response.
Returns:
| Type | Description |
|---|---|
ProxyResponse
|
The current ProxyResponse object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the response has not been set yet. |
session
property
Get the session object, creating it if necessary.
Returns:
| Type | Description |
|---|---|
ClientSession
|
An active ClientSession instance. |
Note
If the session is closed or doesn't exist, a new one will be created using the session factory.
ws_source
property
WebSocketResponse in charge of handling the server side socket with the client.
Returns:
| Type | Description |
|---|---|
WebSocketResponse | None
|
The WebSocketResponse |
ws_target
property
ClientWebSocketResponse in charge of handling the client side socket with the target server.
Returns:
| Type | Description |
|---|---|
ClientWebSocketResponse | None
|
The ClientWebSocketResponse |
__copy__()
Copy the proxy context
Shares the session object, but creates a new instance for the state.
Returns:
| Type | Description |
|---|---|
ProxyContext
|
A ProxyContext instance with a new instance of state, but the same session object. |
Source code in aiorp/context.py
close_session()
async
Close the session object.
This method properly closes the current session and cleans up resources.
set_request(request)
Set the current proxy request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming web request to proxy. |
required |
set_response(response)
Set the current proxy response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
ClientResponse
|
The response from the target server. |
required |
set_socket_pair(ws_source, ws_target)
Set the socket pair used for tunneling messages
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws_source
|
WebSocketResponse
|
The WebSocketResponse to set |
required |
ws_target
|
ClientWebSocketResponse
|
The ClientWebSocketResponse to set |
required |