ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚡️
https://proxyman.io
5.49k stars 180 forks source link

Copy cURL with inline binary data #1501

Open mattijsf opened 1 year ago

mattijsf commented 1 year ago

Description

Currently when copying cURL request with binary data a temporary file is created on the user's desktop and the cURL command looks something like this:

curl 'https://httpbin.org/post' \
-X POST \
-H 'Host: httpbin.org' \
-H 'User-Agent: curl/7.85.0' \
-H 'Accept: */*' \
-H 'Content-Length: 1342' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/octet-stream' \
--data-binary "@/Users/user/Desktop/4DBBCF5D" \
--proxy http://localhost:9090

While is is short, it is not so convenient when having the intention to share the cURL request with someone else due to having a dependency on an external file.

I propose an alternative or extra approach where binary data is part of the copied cURL command by for example utilizing base64. The command could then look something like this:

echo -n "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAX1QTFRF/v7+/////v//4vH94O37/v7/////////////////7/j/v+X+lNP9fcr9////1Oz+fcj70+v9Y7n5Yrn58vn+esH4eMD4////vN77jMX3crbzcLPyh73zt9f38ff9bKrtzuL5TpbozeH4aaTq7fT8tND0f7DsZJ/oPq36KqX6JqP6Jp/3JJ73Nqb4UrP5JZ73I5n0JZr1Zbj4t978xuT8Y7f4T673Ua/3NZ7zHZPyUqz1j8n4c7z3h8b4dLz3jMf4hMT4U6z1MpzzHY7vK5bwfr/2Z7P04vH9/v///f7/4PD9YrH0mcz4SqXyG43vFIbscrb0mcr3isP1zeX7v9769Pn+////icL1nMz3dbj0EoHpRJvuisH0P5ntjML16/T9dbXyh7/0FH7nEn3nYKjvTp7tiL3yosv1oMr1kMLzWaTuJoTnDXfkMIrou9n3rdL2x+D5rdH2utn3C3LhEnbifbPv4e379vn+CGz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jAxOS0wNC0yMy81Yzk0NTk4YzFlMTY3YzY2NGFkZDI0NjllY2YxNjE5YS5pY28ucG5neUBLogAAAABJRU5ErkJggg==" | \
base64 -d | \
curl 'https://httpbin.org/post' \
-X POST \
-H 'Host: httpbin.org' \
-H 'User-Agent: curl/7.85.0' \
-H 'Accept: */*' \
-H 'Content-Length: 1342' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/octet-stream' \
--data-binary @- \
--proxy http://localhost:9090

Why this feature/change is important?

Proxyman offers convenient ways to share requests. This is just another one and especially useful when sharing requests via text/chat and not being dependant on attachments / absolute file paths.

It might only be convenient for relatively small amount of binary data so maybe it should be limited to a length threshold or provided as an extra option to choose from.

NghiaTranUIT commented 1 year ago

It makes sense to support Base 64 Binary data, but I suppose that it's only available for Body Size < 1Mb. I am afraid that it's a huge text if there is no size cap.

If it's > 1Mb, it will fallback to the current behavior.

mattijsf commented 1 year ago

Yes makes sense 👌

NghiaTranUIT commented 1 year ago

@mattijsf let's try this Beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_4.0.0_cURL_with_base64_binary_body.dmg

I adjust the body size cap to 100Kb (not 1Mb as I propose) because the base64 text is enormous, which is impractical to share.

mattijsf commented 1 year ago

Just tested. Including the threshold. Works like a charm.

mattijsf commented 1 year ago

I'm not sure how often people would prefer the filesystem based approach. You could still consider adding it as an (extra) option.

NghiaTranUIT commented 1 year ago

From what I observed, most users would share the cURL. However, the base64 text is huge.

By following the filesystem-based approach, the user can attach the file along with the cURL.

mattijsf commented 1 year ago

Thanks for adding this so quickly. It's a very welcome change when working with encoded/protobuf data.

NghiaTranUIT commented 1 year ago

Can you elaborate on it? @mattijsf

Proxyman has supported Protobuf: https://docs.proxyman.io/advanced-features/protobuf

mattijsf commented 1 year ago

Yes and I use it extensively as I also commented recently here: https://github.com/ProxymanApp/Proxyman/issues/1430#issuecomment-1364734858

I'm just referring to protobuf since it is a binary format, so when I'm collaborating with other developers this feature request helps allot 🙏