Better follow redirection for HTTPClient
#7157
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Solves #7156
First commit adds way to force follow redirections. The RFC document does not allow to redirect request with methods other than GET/HEAD without any user confirmation. To workaround that, and there is now
setFollowRedirects(followRedirects_t follow)
which allow library user to choose between following redirects as RFC allow without user confirmation (default); or force redirects - as user confirmed the redirection. There is stillsetFollowRedirects(bool follow)
left, marked as deprecated.Second commit makes the client follow most other implementations about
302
HTTP code (Found
(1.1), previouslyMoved temporarily
(1.0)). As mentioned already in the RFC:This behavior is required in some cases, even in modern world. My today's example: Google Scripts Apps endpoint. I have
POST
handler setup to run some macro. It should response with JSON containing number of affected rows, but the server handle first POST request (execute macro) and response with redirect request with302
and other location. Then my code needs to GET from the other location. By browsers (Chrome&Firefox) it works just nicely - as they understand 302 "correctly" (well, not in terms of HTTP 1.0). This commit brings this important behavior to the library.Also, there is a small rewrite of
sendRequest
code just to make it more clear, withoutdo {} while();
. Used recursion - as it was also used in other parts. There is only oneint
in this whole function declared, so I think its fine.