[GH-ISSUE #886] scripting, how to rewrite cookie for the reqeust? #882

Open
opened 2026-03-03 19:22:41 +03:00 by kerem · 4 comments
Owner

Originally created by @Thanatos-L on GitHub (May 12, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/886

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (2.25.0)

macOS Version? (mac 11.3)

Steps to reproduce

I am so happy to find an elegance tool.

I have problem about how to set cookie in request.

I have tried:

request.cookies["debug_cookie"] = "new_cookie";
request.cookie["debug_cookie"] = "new_cookie";
request.headers.cookies["debug_cookie"] = "new_cookie";
request.headers.cookie["debug_cookie"] = "new_cookie";

Above code is not work, looking forward reply and thank you for your time!

Expected behavior

Screenshots (optional)

Originally created by @Thanatos-L on GitHub (May 12, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/886 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (2.25.0) ### macOS Version? (mac 11.3) ### Steps to reproduce I am so happy to find an elegance tool. I have problem about how to set cookie in request. I have tried: ``` request.cookies["debug_cookie"] = "new_cookie"; request.cookie["debug_cookie"] = "new_cookie"; request.headers.cookies["debug_cookie"] = "new_cookie"; request.headers.cookie["debug_cookie"] = "new_cookie"; ``` Above code is not work, looking forward reply and thank you for your time! ### Expected behavior ### Screenshots (optional)
Author
Owner

@NghiaTranUIT commented on GitHub (May 12, 2021):

Hey @Thanatos-L

The cookie is actually a key-value on the header, so you can set it like the following code:

request.headers["Cookie"] = "my_key=myvalue";

Example with complex cookies:

request.headers["Cookie"] = "_delighted_web={%2271AaKmxD4TpPsjYW%22:{%22_delighted_fst%22:{%22t%22:%221620801228310%22}}}; first_referer=; first_visit=1620801228;";

You can combine all cookie into a string with ; as a delimiter 👍

<!-- gh-comment-id:839502831 --> @NghiaTranUIT commented on GitHub (May 12, 2021): Hey @Thanatos-L The cookie is actually a key-value on the header, so you can set it like the following code: ```js request.headers["Cookie"] = "my_key=myvalue"; ``` Example with complex cookies: ```js request.headers["Cookie"] = "_delighted_web={%2271AaKmxD4TpPsjYW%22:{%22_delighted_fst%22:{%22t%22:%221620801228310%22}}}; first_referer=; first_visit=1620801228;"; ``` You can combine all cookie into a string with `; ` as a delimiter 👍
Author
Owner

@Thanatos-L commented on GitHub (May 12, 2021):

It works, I have wrong description about the question.

request.headers["Cookie"] = "my_key=myvalue";

Rewrite all my cookies and only my_key=myvalue left.

I need to add new cookie incremental, thank you

<!-- gh-comment-id:839508524 --> @Thanatos-L commented on GitHub (May 12, 2021): It works, I have wrong description about the question. `request.headers["Cookie"] = "my_key=myvalue";` Rewrite all my cookies and only my_key=myvalue left. I need to **add** new cookie incremental, thank you
Author
Owner

@NghiaTranUIT commented on GitHub (May 12, 2021):

So, it would look like:

var newCookie = "my_key=my_value";

// Get your current cookie
var currentCookie = request.headers["Cookie"];

// Add it
currentCookie = currentCookie + "; " + newCookie;

// Override it
request.headers["Cookie"] = currentCookie;
<!-- gh-comment-id:839510668 --> @NghiaTranUIT commented on GitHub (May 12, 2021): So, it would look like: ```js var newCookie = "my_key=my_value"; // Get your current cookie var currentCookie = request.headers["Cookie"]; // Add it currentCookie = currentCookie + "; " + newCookie; // Override it request.headers["Cookie"] = currentCookie; ```
Author
Owner

@Thanatos-L commented on GitHub (May 12, 2021):

Got it, I am not familiar with js so I can not image how to that at the first.

Thanks a lot!

<!-- gh-comment-id:839512933 --> @Thanatos-L commented on GitHub (May 12, 2021): Got it, I am not familiar with js so I can not image how to that at the first. Thanks a lot!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#882
No description provided.