Skip to content

add curl module to rama-http-types #509

@GlenDC

Description

@GlenDC

It's gonna be a relatively small module with 2 methods:

  1. pub fn request_headers_to_curl_command(request: Impl IntoCurlHeadersCommand) -> Result<String, OpaqueError>
  2. 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 any B
    • &Request<B> for any B
  • 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:

Metadata

Metadata

Assignees

Labels

easyAn easy issue to pick up for anyone.good first issueGood for newcomersmentor availableA mentor is available to help you through the issue.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions