ccproxy.core.http_transformers¶
ccproxy.core.http_transformers
¶
HTTP-level transformers for proxy service.
RequestData
¶
Bases: TypedDict
Typed structure for transformed request data.
ResponseData
¶
Bases: TypedDict
Typed structure for transformed response data.
HTTPRequestTransformer
¶
Bases: RequestTransformer
HTTP request transformer that implements the abstract RequestTransformer interface.
Source code in ccproxy/core/http_transformers.py
transform_proxy_request
async
¶
transform_proxy_request(
method,
path,
headers,
body,
query_params,
access_token,
target_base_url="https://api.anthropic.com",
app_state=None,
injection_mode="minimal",
)
Transform request using direct parameters from ProxyService.
This method provides the same functionality as ProxyService._transform_request() but is properly located in the transformer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
HTTP method |
required |
path
|
str
|
Request path |
required |
headers
|
dict[str, str]
|
Request headers |
required |
body
|
bytes | None
|
Request body |
required |
query_params
|
dict[str, str | list[str]] | None
|
Query parameters |
required |
access_token
|
str
|
OAuth access token |
required |
target_base_url
|
str
|
Base URL for the target API |
'https://api.anthropic.com'
|
app_state
|
Any
|
Optional app state containing detection data |
None
|
injection_mode
|
str
|
System prompt injection mode |
'minimal'
|
Returns:
Type | Description |
---|---|
RequestData
|
Dictionary with transformed request data (method, url, headers, body) |
Source code in ccproxy/core/http_transformers.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
transform_path
¶
Transform request path.
Source code in ccproxy/core/http_transformers.py
create_proxy_headers
¶
Create proxy headers from original headers with Claude CLI identity.
Source code in ccproxy/core/http_transformers.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
transform_request_body
¶
Transform request body.
Source code in ccproxy/core/http_transformers.py
transform_system_prompt
¶
Transform system prompt based on injection mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
body
|
bytes
|
Original request body as bytes |
required |
app_state
|
Any
|
Optional app state containing detection data |
None
|
injection_mode
|
str
|
System prompt injection mode ('minimal' or 'full') |
'minimal'
|
Returns:
Type | Description |
---|---|
bytes
|
Transformed request body as bytes with system prompt injection |
Source code in ccproxy/core/http_transformers.py
HTTPResponseTransformer
¶
Bases: ResponseTransformer
HTTP response transformer that implements the abstract ResponseTransformer interface.
Source code in ccproxy/core/http_transformers.py
transform_proxy_response
async
¶
Transform response using direct parameters from ProxyService.
This method provides the same functionality as ProxyService._transform_response() but is properly located in the transformer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_code
|
int
|
HTTP status code |
required |
headers
|
dict[str, str]
|
Response headers |
required |
body
|
bytes
|
Response body |
required |
original_path
|
str
|
Original request path for context |
required |
proxy_mode
|
str
|
Proxy transformation mode |
'full'
|
Returns:
Type | Description |
---|---|
ResponseData
|
Dictionary with transformed response data (status_code, headers, body) |
Source code in ccproxy/core/http_transformers.py
transform_response_body
¶
transform_response_headers
¶
Transform response headers.
Source code in ccproxy/core/http_transformers.py
get_detected_system_field
¶
Get the detected system field for injection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app_state
|
Any
|
App state containing detection data |
None
|
injection_mode
|
str
|
'minimal' or 'full' mode |
'minimal'
|
Returns:
Type | Description |
---|---|
Any
|
The system field to inject (preserving exact Claude CLI structure), or None if no detection data available |
Source code in ccproxy/core/http_transformers.py
get_fallback_system_field
¶
Get fallback system field when no detection data is available.