ccproxy.utils.command_line¶
ccproxy.utils.command_line
¶
Utilities for generating command line tools (curl, xh) from HTTP request data.
generate_curl_command
¶
Generate a curl command from HTTP request parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method (GET, POST, etc.) |
required |
url
|
str
|
Target URL |
required |
headers
|
dict[str, str] | None
|
HTTP headers dictionary |
None
|
body
|
Any
|
Request body (can be dict, str, bytes) |
None
|
is_json
|
bool
|
Whether the body should be treated as JSON |
False
|
pretty
|
bool
|
Whether to format the command for readability |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Complete curl command string |
Source code in ccproxy/utils/command_line.py
generate_xh_command
¶
Generate an xh (HTTPie-like) command from HTTP request parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method (GET, POST, etc.) |
required |
url
|
str
|
Target URL |
required |
headers
|
dict[str, str] | None
|
HTTP headers dictionary |
None
|
body
|
Any
|
Request body (can be dict, str, bytes) |
None
|
is_json
|
bool
|
Whether the body should be treated as JSON |
False
|
pretty
|
bool
|
Whether to format the command for readability |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Complete xh command string |
Source code in ccproxy/utils/command_line.py
generate_curl_shell_script
¶
Generate a shell script with curl command using proper JSON handling.
This creates a more robust shell script that handles JSON safely by: 1. Storing JSON in a variable using heredoc or printf 2. Using the variable in the curl command
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method (GET, POST, etc.) |
required |
url
|
str
|
Target URL |
required |
headers
|
dict[str, str] | None
|
HTTP headers dictionary |
None
|
body
|
Any
|
Request body (can be dict, str, bytes) |
None
|
is_json
|
bool
|
Whether the body should be treated as JSON |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Complete shell script content |
Source code in ccproxy/utils/command_line.py
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 171 172 173 174 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 | |
format_command_output
¶
Format the command output for logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
Request ID for correlation |
required |
curl_command
|
str
|
Generated curl command |
required |
xh_command
|
str
|
Generated xh command |
required |
provider
|
str | None
|
Provider name (optional) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted output string |