I am working on a project where I need to intercept a "fetch" request in javascript and send it as a string to another place where I need to convert it back to a request and execute it. I tried searching online, JSON.stringify() and other Object copying & converting them to string methods doesn't work properly on all cases. Seems like the standard HTTP message format mentioned in RFC https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html is one reliable way. As my understanding is that this is how all requests are converted internally before they are physically transmitted(I may be wrong).
Example If there was a fetch request "GET" for "http://localhost:3000/jk" from an iframe in "http://localhost:3000/static/?appname=test&apphash=abc", the request object in accordance to https://developer.mozilla.org/en-US/docs/Web/API/Request will look something like this, [1]: https://i.stack.imgur.com/MAt61.png
and expected HTTP message string should be something like this(not sure),
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
........
Is there a conversion library/package available in javascript for this or is there any other reliable way to convert an entire request object in javascript(including form details, body etc...) into string in such a way that I can convert them back to request objects. I want to do the same for response objects too ie... convert them to string, transfer it to someplace, and convert back to response object.
This is my first question I apologize if I have not phrased it right or provided enough information and Thanks.