Hi,
I ran into a couple of issues with HTTP POST requests specifically, and wanted to outline them here for reference. Most of these are edge cases, the happy paths seem to work fine. The problems are mostly with redirects, and when sending data to an endpoint that does not return 200
:
Request Body | Response Status | Result |
---|---|---|
yes | 404 or 500 or 308 |
The requestCompleteCallback is never called (both sim and device), but the server receives the request (only the first one in case of the 308). |
yes | 307 |
Crashes simulator, but works correctly on device. |
yes | 301 , 302 , 303 |
Crashes simulator. On device the second request (following the redirect) is a POST but should be a GET (without body). |
empty | 301 , 302 , 303 |
No crash but both sim and device use POST instead of GET when following the redirect (same as above). |
empty | 308 |
Does not follow the redirect. I'd expect this to behave like a 307? |
Regarding changing the method to GET on redirect: this is technically only required for a 303
, but in practice most clients/servers expect this behaviour as well for 301
and 302
, so it would make sense to do this for all of them (on 307
and 308
the method should explicitly stay the same as the original request)
For completeness I used the query method for all of these tests, i.e.:
local conn = http.new("localhost", 80, false)
conn:query("POST", "/foo", nil, "somedata")
n.b. I tested most common permutations for get/post, with/without body, and status 200/404/500 and those all to work correctly.