HttpClient: Add cookie support (cookie jar) #6216
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.
This is a proposal to add cookie support in
HttpClient
. With this modification, the client is able to receive and store cookies and automatically send them in a subsequent request, if applicable as perDomain
andPath
attributes. Receiving multiple cookies in the same response (multipleset-cookie
headers) is supported.Cookie expiry (
Expires
andMax-Age
attributes) is respected, but relies on RTC to be set properly.Secure
is respected,HttpOnly
is stored, but not used anywhere.See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie for a description of cookie attributes.
This proposal probably has room for additions, code style improvements whatsoever. I created this because I needed to handle cookies when dealing with AWS requests and thought others might have use for it. I tried my best to avoid memory leaks or other negative side effects. But I'm not a professional, and it would for sure be useful if others checked a bit upon possible weak spots.
Usage in addition to standard
HttpClient
handling):Declare a cookie jar in the calling instance:
CookieJar cookie_jar;
Before beginning the HTTP request, set
That's it.
The cookie jar is a vector of structs that holds all the cookies of the client and can be used for all requests.
The pull request includes concatenation of received headers, as already proposed in https://github.com/espressif/arduino-esp32/pull/6183. The latter is not required for the cookie jar to work and has only been included since I had mistakenly been working on the master branch of my fork for the former. Sorry for this.