-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better follow redirection for HTTPClient
#7157
Conversation
…write of `sendRequest` function of `HTTPClient`
@PsychoXIVI
|
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
// Here the deprecated function declaration
#pragma GCC diagnostic pop
Nevermind, I see now, other code uses this deprecated function, so I should also update other files. |
Just fix this file, commit your changes and push them to your branch. |
Also changed a bit order of the enums (0 element to be DISABLED)
Also got rid of unnecessary `redirectCount` field. Now redirect counting and limiting is handled in `sendRequest` directly.
I will also update (Sorry for force pushes, I have no other way of testing all the library at the moment...) |
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.