-
-
Notifications
You must be signed in to change notification settings - Fork 71
Description
It's gonna be a relatively small module with 2 methods:
pub fn request_headers_to_curl_command(request: Impl IntoCurlHeadersCommand) -> Result<String, OpaqueError>
pub async fn request_to_curl_command(request impl IntoCurlCommand) -> Result<(String, Request), OpaqueError>
(1) only deals with the headers, so not the body, while (2) deals with the actual body.
That means that (2) needs full access to the body. It doesn't however have to consume or destroy it, so it can return it. But it does make it potentially a more heavy lift process.
-
IntoCurlHeadersCommand
would be a sealed trait and can be implemented for now already for:- request
Parts
- request
&Parts
Request<B>
for anyB
&Request<B>
for anyB
- request
-
IntoCurlCommand` would be a sealed trait and can be implemented for now already for:
Request<Body>
(own it)
Where the latter Body
needs to respect:
Body: rama::http::dep::http_body::Body<Data = bytes::Bytes, Error: Into<BoxError>>
+ Send
+ Sync
And that's about it.
The result should be a valid (one-line) curl command.
Example:
request_headers_to_curl_command(&Request::builder().uri("http://example.com").header("accept", "application/json").body(()).unwrap()).unwrap()
Would result in:
curl --http1.1 -H 'accept: application/json' http://example.com
Make sure to add sufficient test cases in that module.
As icing on the cake you can add a new property curl: <cmd>
to the EchoService
such that services such as https://echo.ramaproxy.org/ will have that info added to the http
object:
{
"http": {
"curl": "curl --http1.1 -H 'accept: application/json' http://example.com",
...
}
...
}
Remarks:
- make sure to have also a look at https://docs.rs/rama/latest/rama/http/io/fn.write_http_request.html as it will show you how you can get the original header order and casing of your request, which is importnat
- pseudo header info you do not need as there is no way to pass this to curl
- tls can be ignored for now as well