WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
254010
Fetch POST Requests Not Working on Safari
https://bugs.webkit.org/show_bug.cgi?id=254010
Summary
Fetch POST Requests Not Working on Safari
Pranay Yadav
Reported
2023-03-15 22:37:13 PDT
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.
Attachments
Add attachment
proposed patch, testcase, etc.
Alexey Proskuryakov
Comment 1
2023-03-16 09:04:41 PDT
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.
Pranay Yadav
Comment 2
2023-03-16 10:35:06 PDT
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}"
Alexey Proskuryakov
Comment 3
2023-03-16 10:47:57 PDT
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>
Radar WebKit Bug Importer
Comment 4
2023-03-22 22:38:13 PDT
<
rdar://problem/107117845
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug