curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder Daniel himself.

Re: How to dynamically generate UUID in curl command (like macros) before sending http request?

From: Timothe Litt <litt_at_acm.org>
Date: Fri, 24 May 2024 15:40:40 -0400

Unix uuidgen should use -r  behavior by default if /dev/{u,]random or
equivalent is available.  It does on the versions that I use.

Otherwise, it uses -t, which is a mix of some hardware (probably primary
network) MAC and time.  In that case, adding -r won't help.

It's not clear why a request ID would need a guaranteed "high-quality"
random uuid.

The UUID is most likely for logging/correlating issues with trouble
tickets or for tying multiple requests together, not crypto.  Any form
of UUID is going to be good enough for that. (Well, maybe if you are
generating unique requests faster than the system clock ticks you might
want to avoid -t.  Seems unlikely.) Anyhow, the default will do the
right thing on the platforms I use.

Yes, it's  rude to post questions to multiple forums, especially without
mentioning it.  Wastes everyone's time.


Timothe Litt
ACM Distinguished Engineer
--------------------------
This communication may not represent the ACM or my employer's views,
if any, on the matters discussed.

On 24-May-24 15:16, Ray Satiro via curl-users wrote:
> On 5/24/2024 2:52 PM, Timothe Litt via curl-users wrote:
>>
>> On most Linux/Unix, use uuidgen.
>>
>> curl -X POST -H "x-client-request-id: {$(uuidgen)}" -d '{"a": 1}'
>> https:/example.com <http://example.com>
>>
>> If you need it for subsequent requests, use
>>
>> UUID="{$(uuidgen)}"
>>
>> curl -X POST -H "x-client-request-id: ${UUID}" -d '{"a": 1}'
>> https:/example.com <http://example.com>
>>
>> and insert $UUID in the cookie/uri/whatever you need for those requests.
>>
>
> Some uuidgen will not be really random unless you use uuidgen -r I
> think. Also, this guy asked the same question in the discussions
> section. [1]
>
> [1]: https://github.com/curl/curl/discussions/13768
>
>

-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2024-05-24