It seems that fetch is not working properly on both ARM and x86 machines, resulting in request bodies not being sent to the intended URL, despite using various code examples and workarounds. The expected request format should look like "POST / HTTP/1.1\r\nHost: localhost:53421\r\nContent-Type: application/json\r\nOrigin: http://localhost:53421\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nAccept: application/json\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15\r\nReferer: http://localhost:53421/\r\nContent-Length: 22\r\nAccept-Language: en-US,en;q=0.9\r\n\r\n{\"get_response\": true}" but the actual request sent is missing the JSON body "POST / HTTP/1.1\r\nHost: localhost:53421\r\nContent-Type: application/json\r\nOrigin: http://localhost:53421\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nAccept: application/json\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15\r\nReferer: http://localhost:53421/\r\nContent-Length: 22\r\nAccept-Language: en-US,en;q=0.9\r\n\r\n" It is important to note that after a certain number of requests, the body is added and it works as expected. It is also worth mentioning that the issue only occurs in safari, and not on other browsers.
Could you please provide some of the examples that don't work? This is very basic functionality, it's fairly unlikely that the issue is so general. There must be some specific detail that triggers the issue.
the following snipped of code is used to make the request : fetch(REQUEST_URL, { method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json", }, body: '{"get_response": true}', }) but the request received on the backend is : "POST / HTTP/1.1\r\nHost: localhost:60145\r\nContent-Type: application/json\r\nOrigin: http://localhost:60145\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nAccept: application/json\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15\r\nReferer: http://localhost:60145/\r\nContent-Length: 22\r\nAccept-Language: en-IN,en-GB;q=0.9,en;q=0.8\r\n\r\n" and after 300+ requests, the body was finally added and the request received on backend was : "POST / HTTP/1.1\r\nHost: localhost:60145\r\nContent-Type: application/json\r\nOrigin: http://localhost:60145\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nAccept: application/json\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15\r\nReferer: http://localhost:60145/\r\nContent-Length: 22\r\nAccept-Language: en-IN,en-GB;q=0.9,en;q=0.8\r\n\r\n{\"get_response\": true}"
So this isn't even a cross-origin request, both are localhost:60145 for you. I cannot reproduce this with these steps: - Put fetch.html (below) in LayoutTests/http/tests in a WebKit checkout. - run-webkit-httpd - load http://127.0.0.1:8000/fetch.html in Safari - terminate run-webkit-httpd - nc -l 8000 - Click the Test button on the page. I always get the request body in nc output. ----- fetch.html <button onclick="test()">Test</button> <script> function test() { fetch("http://127.0.0.1:8000/", { method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json", }, body: '{"get_response": true}', }) } </script>
<rdar://problem/107117845>